我正在尝试创建一个表单以允许用户更改密码:
看法:
- form_tag change_password_users_path do
= error_messages_for :user, :header_message => "Please Try Again", :message => "We had some problems updating your account"
%br
= label_tag :password, "New password:"
= password_field_tag "password"
%br
= label_tag :password_confirmation, "NConfirm new password:"
= password_field_tag "password_confirmation"
%br
= submit_tag "Update Account"
控制器:
def change_password
@user = current_user
if request.post?
@user.password = params[:password]
@user.password_confirmation = params[:password_confirmation]
if @user.save
redirect_to user_path(current_user)
else
render :action => "change_password"
end
end
end
当密码“太短”或密码与确认不匹配时,Authlogic 会捕获验证错误,但在提交表单且两个字段均为空白时不执行任何操作。@user.save 必须返回 true,因为我被重定向到 'user_path(current_user)'。
密码实际上并没有在数据库中更改。
谢谢你的帮助。