我有两个型号的Rails的I18n accepts_nested_attributes_for和error_messages_for
class SurveyResponse
has_many :answers, :class_name => SurveyResponseAnswer.name
accepts_nested_attributes_for :answers
end
class SurveyResponseAnswer
belongs_to :survey_response
validates_presence_of :answer_text
end
在我的嵌套形式,如果验证失败,我得到的屏幕上显示此错误:
“的答案回答的文字不能为空“
我已经使用rails I18n有点成功地定制了我的属性名称。它并不像我期望的那样行事。下面的YML文件不影响属性的名称是如何印在error_messages_for
en:
activerecord:
models:
survey_response:
answers: "Response"
但是,如果从脚本/控制台我尝试
SurveyResponse.human_attribute_name(“答案”)
我得到预期的结果的“回应”。
我希望做的是有验证错误消息说:
“响应答复文件不能为空”。任何想法我需要修复?
3.1中运行良好。谢谢! – 2011-10-14 08:39:18
实际上,不太好:'[DEPRECATION WARNING]不再支持“activerecord.attributes.survey_response”下的嵌套I18n名称空间查找。但是通过[本次讨论](https://github.com/rails/rails/issues/1869),似乎还没有完全正常工作的未被弃用的替代方案。 – 2011-10-14 09:31:41