我想让用户只有在知道他们的旧密码后才能更新他们的密码。目前,我允许用户在不检查旧通行证的情况下更新其密码。你能为我指出正确的方向吗。Rails:更新密码
当前用户更新方法:
def update
if params[:user][:password]
if current_user
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
redirect_to root_url, :notice => "Password has been changed!"
else
render "edit"
end
else
# Something else
end
end
end
(HAML)电流形式:
= form_for @user do |f|
- if @user.errors.any?
- for message in @user.errors.full_messages
= message
.form
= f.password_field :password
= f.password_field :password_confirmation
%input{name: "commit", type: "submit", value: "SAVE CHANGES"}
你有什么试过?另外,忘记旧密码的用户会发生什么情况? –
^还有另一种选择,但我在此将它从更新控制器中删除。我现在试图找出独奏。 –