我有一个“用户”和一个“个人资料”模型。用户与个人资料具有一对一的关系,并且
“accepts_nested_attributes_for 配置文件”。
我正在使用两个复选框验证配置文件 - 也就是说,必须先接受其中一项协议(protocol),然后才能对其进行验证。
无论如何,我想自定义不接受其中一个框的错误消息,所以我将以下内容添加到 en.yml
activerecord:
attributes:
user:
profile:
terms_and_conditions_a:
accepted: "You must accept the terms and conditions to continue"
terms_and_conditions_b:
accepted: "You must accept the terms and conditions to continue"
您会看到配置文件嵌套在用户下 - 这是为了停止将“配置文件”放在错误消息的前面 (as explained here).
这给了我错误:
I18n::InvalidPluralizationData
translation data {:terms_and_conditions_a=>{:invalid=>"You must accept the terms and conditions to continue"}} can not be used with :count => 1
我真的不明白它试图复数,有什么帮助吗?
最佳答案
也许应该是
activerecord:
errors:
models:
user:
profile:
attributes:
terms_and_conditions_a:
accepted: "You must accept the terms and conditions to continue"
而不是
activerecord:
attributes:
user:
profile:
terms_and_conditions_a:
accepted: "You must accept the terms and conditions to continue"
?
这就是我的应用程序中的情况,这无疑是 rails 2 而不是 rails 3。
或者,尝试不要在用户下嵌套配置文件:
activerecord:
errors:
models:
profile:
attributes:
terms_and_conditions_a:
accepted: "You must accept the terms and conditions to continue"
关于ruby-on-rails - 自定义 i18n 错误消息会引发 InvalidPluralizationData 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7838824/