使用Devise更新密码后,如何保持用户登录? [英] How do I keep the user signed in after they update their password using Devise?

查看:103
本文介绍了使用Devise更新密码后,如何保持用户登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户更新密码时,它会将用户签出,并要求他们再次登录。这是我的动作

Whenever a user updates their password, it signs the user out and asks them to sign in again. This is my action

  def update
    @user = User.find(params[:id])
    if @user.update user_params
      sign_in @user, bypass: true # for some reason Devise signs the user out
      redirect_to @user

http://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/SignInOut#sign_in-instance_method

我尝试过 sign_in @user ,但是没有起作用。我试过没有 sign_in ,但也没有工作。我看到这个答案,但它没有帮助:设计是密码更改后注销用户。更新没有密码的用户可以正常工作。 (有一些代码未显示。)

I tried sign_in @user, also, but that didn't work. I tried it without sign_in but that didn't work either. I saw this answer, but it doesn't help: Devise is logging out users after a password change. Updating the user without the password is working OK. (There is some code not shown.)

Devise 3.4.1。

Devise 3.4.1.

推荐答案

我不得不添加一个范围。这是有效的。

I had to add a 'scope`. This worked.

sign_in :user, @user, bypass: true # for some reason Devise signs the user out

请参阅此处的回答: http ://stackoverflow.com/a/11589286/148844

这篇关于使用Devise更新密码后,如何保持用户登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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