Enrique Moreno Tent
Enrique Moreno Tent

Reputation: 25237

Rails i18n - Can't change the format of the errors

In my Rails app, I have the following translation

de:
  activerecord:
    errors:
      models:
        applicant:
          attributes:
            name:
              blank: "Bitte nenne uns Deinen %{attribute}"

But when I check the errors on my models, I get the following message:

Applicant name Bitte nenne uns Deinen Name

How come there is that "Applicant Name" at the beginning of the message?

And how can i remove it?

Upvotes: 5

Views: 1513

Answers (1)

Deepak Mahakale
Deepak Mahakale

Reputation: 23661

You must be using full_messages to show the errors. Something like this:

applicant.errors.full_messages
#=> ["Applicant name Bitte nenne uns Deinen Name"]

Change it to

applicant.errors.messages
#=> ["Bitte nenne uns Deinen Name"]

NOTE: full_messages will append attribute name before error message. That's why you are getting Applicant name appended to the message

Solution2

If you want to change full_messages then try changing

en:
  errors:
    format: "%{attribute} %{message}"

to

en:
  errors:
    format: "%{message}"

Upvotes: 5

Related Questions