我有兩個型號的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