设计重置会话登录 [英] Devise Resetting Session On Login
问题描述
我在 application_controller.rb
文件中定义了以下内容:
I've got the following defined in my application_controller.rb
file:
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete(:return_to)
end
def store_location
session[:return_to] = request.url
end
def after_sign_in_path_for(resource)
r = session[:return_to] || user_root_url
session.delete(:return_to)
r
end
我正在尝试将一个用户发回他们在sign_in之前的地方,或者如果没有保存位置,请将它们发送到他们的根页面。
I'm trying to send a user back to the place they came from before the sign_in, or, if no location is saved, send them to their root page.
我在我的一个控制器中调用它:
I call this in one of my controllers:
if current_user.nil?
store_location
redirect_to home_login_url, alert: "You must be logged in to purchase subscriptions"
return
end
我通过调试器查看了会话[:return_to]
get set,但是登录后, code> after_sign_in_path_for(资源)被调用, session [:return_to]
为null。
I stepped through the debugger and watched the session[:return_to]
get set, but after I log on and the after_sign_in_path_for(resource)
is called, session[:return_to]
is null.
如何在登录名上保留 return_to
变量?
How can I persist the return_to
variable across a login?
我正在运行Rails 3.2.1和Devise 2.1.2
I'm running Rails 3.2.1 and Devise 2.1.2
推荐答案
原来我正在覆盖Devise的入门我的哈希我认为:return_to
是Devise使用的。我最终完全不同,但如果您有问题,请查找名称冲突
Turns out I was overwriting Devise's entry in my hash. I think :return_to
is what Devise uses. I ended up implementing this completely differently, but look for name conflicts if you have a problem
这篇关于设计重置会话登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!