在current_password字段中设计更改验证消息

时间:2014-04-24 09:27:18

标签: ruby-on-rails ruby-on-rails-3 devise

这是我的代码..

<label>Old Password</label>
 <%= f.password_field :current_password, :class=>"myaccount_textbox" %>
<label class="error" for="current_password">
 <%= validation_errors resource.errors['current_password'] %>
</label>
...........

在form-submit上,密码错误,默认验证消息msg - 无效

要求 - 需要更改默认消息

我从link

尝试了{p> devise (3.2.4)rails 3.2.13

在en.yml

en:
  activerecord:
    errors:
      models:
        user:
          attributes:
            current_password:
              confirmation: "Password is incorrect"

目前它不起作用,我只获取默认消息,要做什么更改才能解决这个问题?

2 个答案:

答案 0 :(得分:3)

尝试:

en:
  activerecord:
    attributes:
      user:
        current_password: "Password"
    errors:
      models:
        user:
          attributes:
            current_password:
              invalid: "is incorrect!"

OR

  devise:  
    failure:  
      invalid: 'Password is incorrect!'

请参阅此link,为Devise选择显示密码错误消息的正确选项。

答案 1 :(得分:0)

试试这个

# config/locales/en.yml
    en:
     activerecord:
     attributes:
     user:
         current_password: "Password"
      errors:
        models:
         user:
         attributes:
          current_password:
          confirmation: "is incorrect"