[英]Manually setting return_to with devise
I am currently using Devise to authenticate users on my app. 我目前正在使用Devise在我的应用上验证用户身份。 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: 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!
正如你所看到的,因为动作是一个ajax,我不能使用传统的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. 我知道我可以使用session[:"user.return_to"]
执行此操作,但我无法设置它。 How can I do this? 我怎样才能做到这一点? Or am I going about this all wrong? 或者我这样做是错的?
我相信会话密钥是:"#{scope}_return_to
,它将简单地为:user_return_to
用于User
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.