简体   繁体   中英

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:

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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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