How to change validation messages to forms

the site I am developing will be in Spanish. Therefore, I need error messages in this language.

I created a file in the "Configuration" section called "en.yml" to accomplish this. And I added the following code to it:

es: activerecord: errors: models: announcement: attributes: title: blank: "El título no puede estar vacío." 

"El título no puede estar vacío" means "The name cannot be empty."

When I go and run this code, I see the following message:

"Name El título no puede estar vacío."

Where "Title" is the name of the field. But I do not want it to be displayed. I just want to display the error message I created.

+4
source share
1 answer

You must specify the translation after the attribute

 es: activerecord: models: announcement: "Anuncio" attributes: announcement: title: "Título" # <= here errors: models: announcement: attributes: title: blank: "no puede estar vacío." 

See 5.1 Translations for ActiveRecord Models for more details.

+10
source

Source: https://habr.com/ru/post/1308283/


All Articles