Пользовательское сообщение об ошибке i18n выдает ошибку InvalidPluralizationData? - PullRequest
5 голосов
/ 20 октября 2011

У меня есть модель 'user' и 'profile'. Пользователь имеет один к одному отношения с профилем и "acceptpts_nested_attributes_for профиль".

Я проверяю профиль с двумя флажками - то есть одно из соглашений должно быть принято до его проверки.

В любом случае, я хочу настроить сообщение об ошибке, чтобы не принимать одно из полей, поэтому я добавил следующее в en.yml

activerecord:
  attributes:
    user: 
      profile:
        terms_and_conditions_a: 
          accepted: "You must accept the terms and conditions to continue"
        terms_and_conditions_b: 
          accepted: "You must accept the terms and conditions to continue"

Вы увидите, что профиль вложен под пользователем - это остановит «Профиль», помещенный в начале сообщения об ошибке (как описано здесь).

Это дает мне ошибку:

I18n::InvalidPluralizationData
translation data {:terms_and_conditions_a=>{:invalid=>"You must accept the terms and conditions to continue"}} can not be used with :count => 1

Я действительно не вижу, что он пытается придумать, любая помощь?

1 Ответ

4 голосов
/ 08 февраля 2012

Может быть, это должно быть

activerecord:
  errors:
    models:
      user: 
        profile:
          attributes:
            terms_and_conditions_a: 
              accepted: "You must accept the terms and conditions to continue"

вместо

activerecord:
  attributes:
    user: 
      profile:
        terms_and_conditions_a: 
          accepted: "You must accept the terms and conditions to continue"

Вот так в моем приложении, которое, по общему признанию, является rails 2, а не rails 3.

В качестве альтернативы, попробуйте не вкладывать профиль под пользователем:

activerecord:
  errors:
    models:
      profile:
        attributes:
          terms_and_conditions_a: 
            accepted: "You must accept the terms and conditions to continue"
...