I have never really dealt with or understood the en.yml file as I haven’t used it in the past, today I am trying to change that and customise the validation error messages that are shown when a form submission fails
I have a recipe model, and a form that submits a recipe. At the moment my en.yml file looks like this
en:
activerecord:
models:
recipe:
attributes:
user:
email:
errors:
models:
recipe:
attributes:
dish_name:
blank: "Dont forget to give your Recipe a Dish Name"
Now clearly this is wrong, I was looking for some help on how to layout the file and maybe a explanation on what is going on,ive read the docs but its a little too high level for my skill level when it comes to rails.
Also at the moment if validation fails for dish_name, i.e. its blank I get this error message
Dish name Dont forget to give your Recipe a Dish Name
Any help appreciated
Thanks
You need to override the default format for error messages:
en:
errors:
format: "%{message}"
activerecord:
errors:
models:
recipe:
attributes:
dish_name:
blank: "Dont forget to give your Recipe a Dish Name"
Then you should get the desired meessage:
Dont forget to give your Recipe a Dish Name
Keep in mind this will override the format for other ActiveRecord models as well. Also you need to specify the format for any other locales you will be supporting, otherwise rails will default to showing the attribute.