自定义error_messages_for的标头

时间:2011-04-04 11:59:11

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

我正在尝试使用error_messages_for获取自定义错误消息。我正在使用rails 3并已下载并安装了该插件。 在我看来,我有:

error_messages_for :model

哪个有效并且给我错误消息。但是我想要更改默认

1 error prohibited this model from being saved

我设法使用本地文件更改属性名称:

en:
  activemodel:    
    attributes:
      model:
        dateOfBirth: 'Date of birth'
        etc

但是,当我尝试添加时:

activemodel:
    errors:
      template:
        header:
          one:    "{{model}} is not valid"
          other:  "There are {{count}} errors prohibiting this {{model}} from being saved"
        # The variable :count is also available
        body: "The following fields have problems:"

正如rails guide中所建议的那样,它不会更改标题,我也不会收到新的错误消息。

我已经尝试过activemodel和activerecord。

任何帮助非常感谢

1 个答案:

答案 0 :(得分:2)

我认为问题与我正在使用的插件有关。 Dynamic Form与rails 2.3.x处理错误的方式不完全相同。因为错误不在Active Record范围内。查看此插件附带的语言环境文件:

en:
  errors:
    template:
      header:
        one:    "1 error prohibited this %{model} from being saved"
        other:  "%{count} errors prohibited this %{model} from being saved"
      body: "There were problems with the following fields:"

如果我编辑此文件,那么它可以正常工作。 很快就会看到它是否可以集成到插件中,因此它的工作方式与2.3.x相同

相关问题