Validation 在Rails 3.1中,如何国际化(I18n)验证失败的一般错误消息?

Validation 在Rails 3.1中,如何国际化(I18n)验证失败的一般错误消息?,validation,ruby-on-rails-3.1,nested-forms,Validation,Ruby On Rails 3.1,Nested Forms,我希望能够提供国际化的、有用的错误消息 对于嵌套表单提交,我有一条通用错误消息“部分视图呈现” # _error_messages.html.erb - Fragment ... <strong><%= t('errors.template.body') %> </strong> <ul> <% object.errors.full_messages.each do |msg| %&

我希望能够提供国际化的、有用的错误消息

对于嵌套表单提交,我有一条通用错误消息“部分视图呈现”

    # _error_messages.html.erb - Fragment
    ...

    <strong><%= t('errors.template.body') %> </strong>       
    <ul>
      <% object.errors.full_messages.each do |msg| %>
        <li><%= msg %> </li>
      <% end %>
    </ul>

    ...
我这样写yaml是因为当我检查传递给partial的错误对象时,当我将子对象的名称字段留空(:validates_presence_of:name)时,看起来如下所示:

#<ActiveModel::Errors:0x007111111C111111 @base=#<FamilyWizard id: nil, ...>, 
    @messages {:children=>["must not be blank"]}>
en:
  errors: &errors
    format: ! '%{attribute} -- %{message}'
      messages:
        accepted: must be accepted
        blank: must not be blank
        body: ! 'There were problems with the following fields:'


  activerecord:
    attributes:
      family_wizard: 
        children: kids

#)是正确的,但它缺少我想要的activemodel/activerecord验证部分

这个问题的答案是,由于我的yaml文件有两个问题,所以我的作用域是错误的。错误的间距和错误的标签。它应该是activerecord而不是activemodel,并且activerecord范围应该与树中的错误范围处于同一级别

要转换模型的属性(即,从子对象转换为子对象),yaml如下所示:

#<ActiveModel::Errors:0x007111111C111111 @base=#<FamilyWizard id: nil, ...>, 
    @messages {:children=>["must not be blank"]}>
en:
  errors: &errors
    format: ! '%{attribute} -- %{message}'
      messages:
        accepted: must be accepted
        blank: must not be blank
        body: ! 'There were problems with the following fields:'


  activerecord:
    attributes:
      family_wizard: 
        children: kids
帮助我得到答案的两个资源是:

什么是“错误:&errors”“&errors”有帮助?你能解释一下吗?