我怎样才能完全改变"密码不匹配确认"错误消息activerecord

时间:2014-04-24 08:48:24

标签: ruby-on-rails activerecord

YML

en   
  activerecord:
    errors: 
      models: 
        user:
          confirmation: "Passwords do not match"

但我得到

  

“密码密码不匹配”

我怎么能摆脱“密码”?

2 个答案:

答案 0 :(得分:5)

试试这个:

# config/locales/en.yml
en:
  activerecord:
    attributes:
      user:
        password_confirmation: "Passwords"
    errors:
      models:
        user:
          attributes:
            password_confirmation:
              confirmation: " do not match!"

答案 1 :(得分:3)

我能给出的最好的方法是从错误消息中删除该属性(所以你只收到消息) - removing field name from validation error message

这是我们在Rails 4.0.2中使用的内容:

<% resource.errors.each do |attr,msg| %>
    <li><%= msg %></li>
<% end %>