Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find a list of Rails error messages keys?

I'm trying to customize my error messages by modifying en.yml.

en:
  errors:
    messages:
      blank: "This is a required field."

And now, every empty field that has the validates presence: true validator shows this new message.

I want to find a list of messages types to modify. For example, how can I customize the numericality validator message? Or the greater_than validator?

Any suggestions where to find this?

like image 556
sergserg Avatar asked Jul 28 '13 03:07

sergserg


1 Answers

Here is a list of the messages you can customize in the en.yml file:

validates_acceptance_of
`:accepted` (“must be accepted”)
validates_associated
`:invalid` (“is invalid”)
validates_confirmation_of
`:confirmation` (“doesn’t match confirmation”)
validates_exclusion_of
`:exclusion` (“is reserved”)
validates_format_of
`:invalid` (“is invalid”)
validates_inclusion_of
`:inclusion`(“is not included in the list”)
validates_length_of
`:too_short` (“is too short (minimum is {{count}} characters)”)
`:too_long` (“is too long (maximum is {{count}} characters)”)
validates_length_of (with :is option)
`:wrong_length` (“is the wrong length (should be {{count}} characters)”)
validates_numericality_of
`:not_a_number` (“is not a number”)
validates_numericality_of (with :odd option)
`:odd` (“must be odd”)
validates_numericality_of (with :even option)
`:even` (“must be even”)
validates_numericality_of (with :greater_than option)
`:greater_than` (“must be greater than {{count}}”)
validates_numericality_of (with :greater_than_or_equal_to option)
`:greater_than_or_equal_to` (“must be greater than or equal to {{count}}”)
validates_numericality_of (with :equal_to option)
`:equal_to` (“must be equal to {{count}}”)
validates_numericality_of (with :less_than option)
`:less_than` (“must be less than {{count}}”)
validates_numericality_of (with :less_than_or_equal_to option)
`:less_than_or_equal_to` (“must be less than or equal to {{count}}”)
validates_presence_of
`:blank` (“can’t be blank”)
validates_uniqueness_of
`:taken` (“has already been taken”)
like image 82
sergserg Avatar answered Nov 12 '22 09:11

sergserg