Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom i18n error message gives throws InvalidPluralizationData error?

I have a 'user' and a 'profile' model. The user has one to one relationship with profile and "accepts_nested_attributes_for profile".

I'm validating profile with two checkboxes - that is to say one of the agreements must be accepted before it's validated.

Anyway, I want to customise the error message for not accepting one of the boxes so I added the following into 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"

You'll see that profile is nested under user - this is to stop "Profile" being put at the front of the error message (as explained here).

This gives me the error:

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

I don't really see what it's trying to pluralize, any help?

like image 721
digitalWestie Avatar asked Oct 09 '22 17:10

digitalWestie


1 Answers

Maybe it should be

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

rather than

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

?

That's how it is in my app, which is admittedly rails 2 rather than rails 3.

Alternately, try not nesting profile under user:

activerecord:
  errors:
    models:
      profile:
        attributes:
          terms_and_conditions_a: 
            accepted: "You must accept the terms and conditions to continue"
like image 52
Max Williams Avatar answered Oct 13 '22 11:10

Max Williams