我有'用户'和'个人资料'模型。用户与个人资料和一对一关系 “accepts_nested_attributes_for profile”。
我正在使用两个复选框验证配置文件 - 也就是说,在验证之前必须接受其中一个协议。
无论如何,我想自定义错误消息,因为我不接受其中一个框,所以我将以下内容添加到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
我真的没有看到它试图复数,有什么帮助吗?
答案 0 :(得分:4)
也许它应该是
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"