Rails I18n accepts_nested_attributes_for and error_messages_for

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-06-17T04:56:05Z Indexed on 2010/06/17 5:03 UTC
Read the original article Hit count: 361

I've got two models

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

In my nested form if validation fails I get this error displayed on the screen:

"answers answer text can't be blank"

I've customized my attribute names somewhat successfully using rails I18n. It doesn't behave exactly how I would expect though. The yml file below doesn't affect how the attribute name is printed in error_messages_for

en: 
  activerecord:
    models:
      survey_response:
        answers: "Response"

But if from script/console I try
SurveyResponse.human_attribute_name("answers")

I get the expected result of "Response".

What I'd like to do is have the validation error message say:

"Response answer text can't be blank". Any ideas what I need to fix?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about i18n