使用Devise更新密码后,如何让用户保持登录状态?

每当用户更新其密码时,它都会向用户签名并要求他们再次登录。 这是我的行动

users_controller.rb

  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 @usersign_in @user 。 我尝试了没有sign_in但这也没有用。 我看到了这个答案,但它没有帮助: Devise在密码更改后注销用户 。 没有密码更新用户正常。 (有些代码没有显示。)

设计3.4.1。

我不得不添加’范围’。 这很有效。

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

请在此处查看答案: https : //stackoverflow.com/a/11589286/148844

修改用户参数后,将其签出(不是强制性的,但会减少很多混淆),并重新签名。此外,您缺少范围。 改为使用它:

 def update if current_account.update_with_password(params[:account]) sign_out(current_account) sign_in(:account, current_account, :bypass => true) flash[:notice] = 'Password updated.' redirect_to account_path else render :action => :show end end 

看原始问题 。