标题有点困惑,所以我会解释一下。
我有以下 Controller 方法:
def password_update
@op = params[:old_password]
@np = params[:new_password]
@cp = params[:confirm_password]
if @np == @cp
if !@np.empty?
if current_user.update_with_password(:current_password=> @op)
current_user.password = @np
if current_user.save
flash[:notice] = "Password Successfully Changed"
redirect_to settings_path and return
end
else
flash[:notice] = "Incorrent Current Password"
redirect_to change_password_path and return
end
else
flash[:notice] = "New Password Cannot Be Blank"
end
elsel
flash[:notice] = "Incorrect Password Confirmation"
end
redirect_to change_password_path
end
其他一切都很好,这意味着我有工作路线和 View ,可以将您带到此方法并在提交表单时调用它。但是,当我尝试正确更改密码时,就会出现错误。顺便说一句,我正在使用设计。当我单击提交时,我退出并显示“您必须登录才能完成此操作”。所以我尝试登录,我当前的密码不起作用。它更改了我的密码(更改为我在表单中设置的密码)!它告诉我我必须登录(当我尝试更改密码时我就是这样)但它仍然会更改它。
欢迎任何帮助,但是,我是新手,非常感谢详细的解释。谢谢!
最佳答案
我相信 Devise wiki 中的这个页面可以回答您的问题:https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password
这段代码特别
if @user.update_attributes(params[:user])
# Sign in the user by passing validation in case his password changed
sign_in @user, :bypass => true
redirect_to root_path
else
render "edit"
end
绕过选项似乎也很好命名。希望这可以帮助。干杯
关于ruby-on-rails - 如何通过设计和更新绕过辞职,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111263/