我在"How to allow users to edit their password (Solution 3)"上关注了Devise的wiki。但是,如果密码不符合某些要求(例如6个字符而不是8个字符),则wiki中提供的默认视图代码不会显示错误消息。因此,我在表单中添加了以下行:-if devise_error_messages? = devise_error_messages!
:
= form_for(@user, :url => { action: "update_password" } ) do |f|
-if devise_error_messages?
= devise_error_messages!
.field
= f.label :current_password
= f.password_field :current_password
.field
= f.label :password, "Password"
= f.password_field :password, :autocomplete => "off"
.field
= f.label :password_confirmation
= f.password_field :password_confirmation
.action_container
= f.submit
然而,这会返回错误undefined local variable or method 'resource' for #<#<Class:0x007f974d2b8ae0>:0x007f974d3f8888>
答案 0 :(得分:0)
这条线解决了这个问题:
-if not @user.errors.empty?
= @user.errors.full_messages.map { |msg| msg }.join