我有一个自定义控制器,可以根据代码here处理用户密码的编辑。设计不验证密码/密码确认
用户模型
attr_accessible :password, :password_confirmation, :username, :login
...
devise :database_authenticatable,
:lockable,
:registerable,
:recoverable,
:rememberable,
:trackable
PasswordsController
expose(:user) { current_user }
def update
if user.update_with_password(params[:user])
sign_in(user, :bypass => true)
flash[:notice] = "success"
else
render :edit
end
end
我改密码表单位于here。
问题是无论我输入什么(或不输入该事项)到编辑密码表单中,都会显示“成功”闪存方法。
是否所有的工作,但它应该如何?如果确认字段不匹配或者current_password错误,它不会更改密码? – Dex
它仍会将其更改为:无论密码如何(如果有的话)都在:password_confirmation中。 –
如果将if语句更改为'if params [:user] [:password] == params [:user] [:password_confirmation]'并将'user.update_with_password(params [:user])''更改为body ? –