开发者

Manually setting return_to with devise

I am currently using Devise to authenticate users on my app. It's working great for the most point, but I am having trouble with a specific action:

view:

<p id="save"><%= link_to "Save", new_save_path, :remote => true %></p>

saves_controller.rb:

def new
  if user_signed_in?
    @save = Save.create(:user_id => current_user.id)
    render :update do |page|
      page.replace_html "save", "Saved!"
    end
  else
    redirect_to new_user_session_path, :notice => "You need to sign in to do that."
  end
end

As you can see, because the action is an ajax one, I can't use the traditional before_开发者_如何学运维filter :authenticate_user! method. So instead I am redirecting the user to the sign in page.

The problem is, I want to automatically redirect the user back to the previous page when they logged in.

I understand I can do this with the session[:"user.return_to"] but I'm having trouble setting it. How can I do this? Or am I going about this all wrong?


I believe the session key is :"#{scope}_return_to, which will be simply :user_return_to for a User class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜