Rails I18n accepts_nested_attributes_for and error_messages_for

两盒软妹~` 提交于 2019-11-28 06:28:30

Try this:

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

I am using Rails 3 and this is working for me (my i18n file is a bit different, using "attributes" instead of models. I don't know if this works in 2.3)

en: 
  activerecord:
    attributes:
      survey_response:
        answers:
          answer_text: "Response"

Before that I was trying to create a attribute in the yml called "answers_answer_text" but it was not working.

I hope this solves your issue.

As of Rails 3.2.0, the i18n yaml has changed to

en: 
  activerecord:
    attributes:
      survey_response:
        foo: "Foo"
      survey_response/answers:
        answer_text: "Response"

(Note the slash.) This also permits you to define an attribute name on the collection itself, e.g.

en: 
  activerecord:
    attributes:
      survey_response:
        foo: "Foo"
        answers: "Ripostes"
      survey_response/answers:
        answer_text: "Response"

Source: https://github.com/rails/rails/pull/3859

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!