注销后重定向设备
在用户注销后,使用 Devise 将用户重定向回当前所在的页面的最佳做法是什么?
设计文档说要覆盖以下内容(在您的应用程序控制器中):
def after_sign_out_path_for(resource_or_scope)
# logic here
end
这很容易。但是,我将上一页设置为会话变量,如下所示:
session[:return_to] = request.fullpath
问题是,当您注销时,会话将被销毁,并且顶部方法在会话被销毁后发生,这意味着您不再有权访问它。我正在考虑将其放入类变量或类似的变量中,但想看看 SO 的想法。
What's the best practice for redirecting the user, using Devise, back to the page she is currently on after she logs out?
The devise docs say to override the following (in your application controller):
def after_sign_out_path_for(resource_or_scope)
# logic here
end
Which is easy enough. However, I'm setting the previous page to be a session variable, like this:
session[:return_to] = request.fullpath
The problem is that when you sign out, the session is destroyed, and the top method occurs AFTER the session is destroyed, meaning you no longer have access to it. I'm thinking of putting it in a class variable or something similar, but wanted to see what SO thought.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您始终使用单击注销链接的页面,则可以在请求中使用引荐来源网址。
If you are always using the page where the logout link was clicked you could use the referrer on the request.
如果您想在注销后将用户重定向到登录页面,请在应用程序控制器中写入以下函数
if you want to redirect user to sign in page after sign out write the below function in you application controller