Kyl*_*cot 33 ruby-on-rails devise ruby-on-rails-3
我有一个处理基于断码的用户密码的编辑定制控制器在这里.
用户模型
attr_accessible :password, :password_confirmation, :username, :login
...
devise :database_authenticatable,
:lockable,
:registerable,
:recoverable,
:rememberable,
:trackable
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
我的编辑密码表单位于此处.
问题在于,无论我输入(或不输入该内容)到编辑密码表单中,都会显示"成功"闪存方法.
sar*_*dne 68
如果您希望Devise进行验证,则需要将:validatable模块添加到模型中.这很容易做到,只需添加:validatable到devise调用中的模块列表中,因此您的模型说:
devise
:database_authenticatable,
:lockable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable
Run Code Online (Sandbox Code Playgroud)
这将使设计添加验证.
另一种简单的方法是添加自己的验证.如果您只想验证密码确认是否匹配,可以validates_confirmation_of通过将其添加到模型中来添加验证:
validates_confirmation_of :password
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助.
我认为您忘记了在Rails 4的application_controller.rb中初始化强参数
before_action:configure_permitted_parameters,如果::devise_controller?受保护的
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up){|u|u.permit(:email,:password,:password_confirmation)}
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20129 次 |
| 最近记录: |