Skip to content

Where to find Rails’ default validation error messages

I’ve been playing around with simple_form and I18n in Rails a LOT in a recent project. I’ve been customising form labels and validation messages using the internationalisation features – it works really, really well.  There is, however, one small problem.  When you start, you are presented with an almost blank YAML file and some very flakey documentation at the bottom of the simple_form readme.  How do you know how to structure that YAML file?  What attribute names should you use?

One of the best resources I’ve found so far are the defaults files in the Rails source code.

That gives you a full list of the attribute names to use for different validators.  For example, if you’re using a validates_format_of validator, you can quickly see that you need to use the invalid YAML attribute.  Good luck guessing that one!

The looking at the source trick can also be very useful for gems.  I’ve spent ages Googling for the correct YAML attribute to use for the validates_email_format_of gem with absolutely no luck whatsoever.  30 seconds on Github and I find the source file which tells me the attribute for an invalid email address is invalid_email_address.