Does anyone have a few tips on how to translate model associations in Rails?
For example: I have a Person model that can have many phones. However, a person must have at least one Phone. I can not translate this check. The best I could do is the following:
validates_presence_of :phones, :message => "At least one phone is required."
And on my YAML, I replaced this line to omit %{attribute} :
format: ! '%{message}'
This way only my message is displayed, and I avoid the display name of the untranslatable field.
It causes me a lot of headache, because some stones just do not allow me to go through :message => "something describing the error" , so I wanted to configure all error messages through my YAML.
In addition, with some models I can translate their attributes, but with others - not. For example:
activerecord: attributes: additional_info: account_manager: "Manager"
It works. I can see the "Manager" in my form. However, when this field has an error, Rails will display it as "Additional info account manager can't be blank" .
I tried this:
activerecord: errors: models: additional_info: attributes: account_manager: "Manager"
But no luck.
I read the docs, but donβt know why this is happening.
Nicholas pufal
source share