Change default validation error messages.

Hi all,

I was wondering if it was possible to globally change the Rails validation error messages?

For example, when I enter a blank field I get the message:

"Caption can't be blank"

I'd like for blank fields to show

"Caption is a mandatory field"

I know I can give each validation a custom error message, but I'd like to change it globally.

Cheers, Diego

I got a hack. Somewhere in enviornment.rb set a bunch of global variables with your custom error messages. Then in each model, set the error message to the global variable.

If you go to http://dev.subimage.com/projects/substruct and look at the CVS, you can see it done there.

David

Hey Diego, you can simply add the following to your validation:

:message => "My validation message."

e.g.

validates_presence_of :name, :message => "Name field cannot be blank."

Good luck,

-Conrad

validates_presence_of :caption, :message => “is a mandatory field”

Don’t add the field name as part of the message because it gets added to the attribute already as errors#each_full [which is what normally gets called IIRC]. Even if you write your own error message handling you’re better off not adding the attribute name and just using errors#each_full. YMMV

RSL

Thanks Russell and all others for taking the time to reply. I will give these a try.