开发者

Redirect to original destination after logging in

Rails 2.3.11

If a user tries to go to /photos when they aren't logged in, they are directed to [site]/admin/login?route=[site]/photos. After they log in, I would like them to be sent to whatever was defined in "route" instead of the default home page.

In /app/controllers/admin_controller.rb:

def login
    if session[:user_id] #already logged in
      redirect_to ''
    @destination = request.url
    end
    if reque开发者_Go百科st.post?
      if [authentication code]
        if user.activated? #check to see whether the user has activated their account
          session[:user_id] = user.id
          if params[:route] # ********
            redirect_to "#{params[:route]}"
          else
            redirect_to :controller => 'home'
          end
        else
          flash.now[:notice] = "Your account hasn't been activated yet.  Check your emails!"
        end
      else
        flash.now[:notice] = "Invalid email/password combination"
      end
    end
  end

The "*"ed line is the one that isn't working correctly. When I check to see the parameters, :route isn't among them, so the argument isn't being passed in with the login post. Can anyone explain to me why it isn't and how I could fix it?

Thank you!


You could do something like:

session[:return_to] ||= request.referer
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜