我没有设法从简单表单更改默认错误消息,我尝试编辑简单表单语言环境文件,但它似乎被忽略了
这是我的语言环境文件:
#config/locales/simple_form.en.yml
en:
simple_form:
error_notification:
default_message: "A custom message:"
但我仍然收到“请查看以下问题:”
有谁知道我做错了什么?
最佳答案
更改您的 :default_message
至 :your_model_name
如您所见 in the source , error_notification
方法使用 translate_error_notification
从 YAML 文件中获取翻译。
def translate_error_notification
lookups = []
lookups << :"#{object_name}"
lookups << :default_message
lookups << "Please review the problems below:"
I18n.t(lookups.shift, scope: :"simple_form.error_notification", default: lookups)
end
对于
user
型号 lookups
包含:lookups == [:user, :default_messge, "Please review the problems below:]
每个对象的翻译可能不同,因此调用此事务:
#config/locales/simple_form.en.yml
en:
simple_form:
error_notification:
user: "A custom message:"
投票是否有帮助;)
关于ruby-on-rails - 使用 simple_form 更改默认错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15328516/