注销后重定向设计 [英] Redirecting Devise After Sign Out
问题描述
注销后,使用Devise将用户重定向到当前页面的最佳做法是什么?
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
问题在于,当您注销时,会话被破坏,并且顶级方法在之后发生会话已被破坏,这意味着您将无法再访问它。我正在考虑将其放在类变量或类似的变量中,但想查看SO的想法。
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.
推荐答案
如果始终使用单击注销链接的页面,您可以在请求中使用引荐来源网址。
If you are always using the page where the logout link was clicked you could use the referrer on the request.
def after_sign_out_path_for(resource_or_scope)
request.referrer
end
这篇关于注销后重定向设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!