Ruby-on-rails 如何将 Rails 会话 cookie 过期时间设置为“会话”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12880623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:51:46  来源:igfitidea点击:

How to set rails session cookie expiration time to "session"

ruby-on-railsrubysessionsession-timeout

提问by Lanbo

I'm not very experienced with the parts of Rails that are not on the surface.

我对 Rails 表面上的部分不是很有经验。

All I want is to have a session cookie that has the expiration set to sessionso it expires when the user leaves their browser or whatever. As a security measurement.

我想要的只是有一个会话 cookie,它的过期时间设置为session当用户离开浏览器或其他任何东西时它会过期。作为安全措施。

回答by Roman

By default the cookie is a session cookie. You have complete control over the cookie by providing an options hash in config/initializers/session_store.rb. The options are the same as to Rack::Session::Cookie(see docs). So for example, for a specific expiration date you can provide :expire_after.

默认情况下,cookie 是会话 cookie。通过在 中提供选项哈希,您可以完全控制 cookie config/initializers/session_store.rb。选项与 to 相同Rack::Session::Cookie参见文档)。例如,对于特定的到期日期,您可以提供:expire_after.

If you're using Devise, and rememberablestrategy, then there's another cookie which can be used in order to retrieve the user.

如果您使用Deviserememberablestrategy ,那么还有另一个 cookie 可用于检索用户。