简体   繁体   English

在为Devise中的用户做手动sign_in时,你怎么设置记住我是?

[英]When doing a manual sign_in for the user in Devise, how can you set remember me to yes?

In Devise , I'm signing in my user like this: Devise中 ,我正在以这样的方式登录我的用户:

sign_in_and_redirect(:user, user)

In the default sign in page, there's a checkbox that the user can select so that they don't have to sign in again when they return to the site. 在默认登录页面中,有一个用户可以选择的复选框,以便他们在返回站点时不必再次登录。 But when you do the sign in with the sign_in_and_redirect(:user, user) line, I can't work out how to set that parameter to yes. 但是,当您使用sign_in_and_redirect(:user, user)行登录时,我无法确定如何将该参数设置为yes。 Does anyone know how? 有谁知道怎么样? Thanks for reading. 谢谢阅读。

Did some testing. 做了一些测试。 Presenting the findings for others. 向他人介绍调查结果。

The simplest solution, assuming the user object has the rememberable module defined on the devise declarable, is to set remember_me to true on the user before sign in and redirect: 假设用户对象具有在devise上定义的可记忆模块,最简单的解决方案是在登录和重定向之前将remember_me设置为true:

@user.remember_me = true
sign_in_and_redirect(@user, :event => :authentication)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM