Rails i18n特定的错误验证格式

and*_*orp 13 ruby validation activerecord ruby-on-rails internationalization

因此,您可以使用以下内容更改en.yml中的错误消息:

en:
  activerecord:
    errors:
      models:
        foo:
          attributes:
            amount:
              greater_than_or_equal_to: "Custom GTOE error message."
Run Code Online (Sandbox Code Playgroud)

但是,这将说明以下内容:

Amount Custom GTOE error message.
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过以下方式全局删除它:

en:
  activerecord:
    errors:
      format: "%{message}"
Run Code Online (Sandbox Code Playgroud)

但是,我可以%{attribute}只为此验证而重做吗?

谢谢!

Den*_*rov -5

 validates :amount, :numericality => { :greater_than_or_equal_to => YOUR_VALUE, :message => YOUR_ERROR_MESSAGE }
Run Code Online (Sandbox Code Playgroud)