注销后重定向设备

发布于 2024-11-17 18:06:38 字数 498 浏览 1 评论 0原文

在用户注销后,使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半世晨晓 2024-11-24 18:06:38

如果您始终使用单击注销链接的页面,则可以在请求中使用引荐来源网址。

def after_sign_out_path_for(resource_or_scope)
  request.referrer
end

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
看透却不说透 2024-11-24 18:06:38

如果您想在注销后将用户重定向到登录页面,请在应用程序控制器中写入以下函数

  def after_sign_out_path_for(resource_or_scope)
    new_user_session_path
  end

if you want to redirect user to sign in page after sign out write the below function in you application controller

  def after_sign_out_path_for(resource_or_scope)
    new_user_session_path
  end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文