This has been bugging me for a while. This problem occurs with all of my models, but i'll use one of them, Quiz, as an example.
Quiz has the following validations:
validates_presence_of :size, :style
I'm using I18n, and i have the following set in my translations file: (these are just the standard error messages, but i've included them in my en.yml so that it's easy to see the structure, if i want to override them for any particular model)
activerecord:
errors:
messages:
inclusion: "{{attribute}} is not included in the list"
invalid: "{{attribute}} is invalid"
empty: "{{attribute}} can't be empty"
blank: "{{attribute}} can't be blank"
record_invalid: "Validation failed: {{errors}}"
The problem is this: if i make a new quiz, which will fail validation, then look at quiz.errors.full_messages, each error message has the attribute then the full message:
>> quiz = Quiz.create
=> <unsaved quiz object>
>> quiz.errors.full_messages
=> ["Size Size can't be blank", "Style Style can't be blank"]
I don't understand why the message is, for example, "Size Size can't be blank"
and not "Size can't be blank"
Any ideas anyone?
There should be also:
en:
errors:
# The default format to use in full error messages.
format: "%{attribute} %{message}"
And your other translations shouldn't include %{attribute}
anymore.
To make sure you get all correctly use en.yml
from your Rails version,
it is located at: lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/locale/en.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With