我正在尝试使用 i18n 自定义验证错误消息。
假设我有一个地址模型,用于验证 zip_code
是否存在。
我的 config/locales/activerecord.fr.yml
看起来像这样
fr:
activerecord:
errors:
models:
address:
attributes:
civility:
blank: "Some message"
如果我验证失败,@address.errors.full_messages
中的错误消息将是:
“邮政编码一些消息”
为什么邮政编码
会添加到我的错误消息中?我怎样才能避免这种行为?
最佳答案
您只需添加:
errors:
format: "%{message}"
这样您将只显示没有属性名称的错误消息。
编辑:这应该添加到 config/locales/fr.yml
而不是 config/locales/activerecord.fr.yml
(其中也有 错误:
)
关于ruby-on-rails - ActiveRecord 验证 : String added to error message in locales,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46325571/