【发布时间】:2014-08-06 16:09:46
【问题描述】:
由于某种原因,我可以成功自定义 ActiveRecord 中的特定错误消息,但我似乎无法更改错误消息标题。
en:
activerecord:
errors:
template:
header:
one: "Custom message goes here. 1 error prohibited this %{model} from being saved"
other: "Customer message goes here. %{count} errors prohibited this %{model} from being saved"
messages:
blank: "custom :blank message goes here"
models:
complaint: "Complaint"
attributes:
complaint:
city: "Custom city name"
neighborhood: "Custom neighborhood name"
如果我将城市和社区留空,我会收到以下错误消息:
2 个错误导致此投诉无法保存:
自定义城市名称自定义:此处为空白消息
自定义社区名称自定义:此处为空白消息
由于某种原因,实际的错误消息已更改,但错误标头并未更改。在调试的时候,我把YML文件改成如下,没有改变默认消息:
en:
activerecord:
errors:
template:
header:
one: "blah"
other: "blah blah"
body: "blah blah blah"
有谁知道为什么这个简单的改变不起作用?我唯一能想到的是“标题”需要与模型相关联。不确定。
我使用的参考资料:
[http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models][1] [http://guides.rubyonrails.org/v2.3.8/i18n.html#translations-for-active-record-models][1]
【问题讨论】:
标签: ruby-on-rails ruby activerecord