Not including field names in validation error messages

If I have the following check:

validates_inclusion_of :dob, :in => Date.new(1900)..Time.now.years_ago(18).to_date, :message => "You must be 18 or older to register"

Actual message on the site that appears:

"Dob You must be 18 years old or older to register"

Is there a way to not include the column name at the beginning of the message?

thanks

Tom

+3
source share
2 answers

Yes. I am using the custom-err-msg plugin . It's very easy to get up and run, just read the README.

+3
source

Full disclosure: I designed the gem.

I feel that the existing solutions are hacks, and I designed this stone to avoid such hacks.

https://github.com/lulalala/adequate_errors

gem yaml locale :

en:
  activemodel
    adequate_errors:
      models:
        user:
          attributes:
            dob:
              inclusion: "You must be 18 or older to register"

model.errors.adequate.messages .

0

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


All Articles