清除 Rails 中基于 cookie 的会话存储的命令 [英] Command to clear the cookie-based session store in Rails

查看:61
本文介绍了清除 Rails 中基于 cookie 的会话存储的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常想清除 Rails 中的会话存储,尤其是默认的基于 cookie 的会话存储.有些网站似乎建议

I often want to clear the session store in Rails, in particular, the default cookie-based session store. Some sites seem to suggest that

rake tmp:sessions:clear

完成了这个任务,但似乎没有.清除基于 cookie 的会话存储的正确方法是什么?

accomplishes this task, but it appears that it does not. What is the proper way to clear the cookie-based session store?

推荐答案

问题在于 cookie 是客户端.显然,在您的服务器上运行 rake 任务不会删除所有访问过该网页的机器上的 cookie.

The problem is that cookies are client side. Running a rake task on your server won't delete cookies on all the machines that have visited the web page, obviously.

也许你可以在你的控制器中使用 session.clear ?不过,您更改 cookie 密钥是正确的.这样做会使属于旧密钥的任何会话无效.你必须从 ActionController::StaleSession(或类似的东西)中拯救出来,但它会起作用.

Perhaps you can use session.clear in your controllers somehow? You're right about changing the cookie key, though. Doing so would invalidate any session belonging to the old key. You would have to rescue from ActionController::StaleSession (or something like that), but it'd work.

这篇关于清除 Rails 中基于 cookie 的会话存储的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆