Tag: 错误消息

Rails I18n accepted_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 在我的嵌套表单中,如果validation失败,我会在屏幕上显示此错误: “答案答案文字不能为空” 我使用rails I18n成功地定制了我的属性名称。 它的行为并不像我期望的那样。 下面的yml文件不会影响error_messages_for中打印属性名称的方式 en: activerecord: models: survey_response: answers: “Response” 但是,如果从脚本/控制台我尝试 SurveyResponse.human_attribute_name( “答案”) 我得到了“响应”的预期结果。 我想做的是validation错误消息说: “响应答案文本不能为空”。 我需要解决的任何想法?