# Change default validation error messages.

**URL:** <https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381>\
**Category:** rubyonrails-talk\
**Created:** [February 27, 2007, 5:38am UTC](https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381 "2007-02-27T05:38:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discuss.rubyonrails.org/u/Diego)\
**Post date:** [February 27, 2007, 5:38am UTC](https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381/1 "2007-02-27T05:38:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DKG](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@DKG](https://discuss.rubyonrails.org/u/DKG)\
**Post date:** [February 27, 2007, 5:54am UTC](https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381/2 "2007-02-27T05:54:28Z")

</div>

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](http://dev.subimage.com/projects/substruct) and look at the CVS, you can see it done there.

David

---

<div class="post-metadata">

**Author:** ![Con](https://avatars.discourse-cdn.com/v4/letter/c/9fc29f/32.png) [@Con](https://discuss.rubyonrails.org/u/Con)\
**Post date:** [February 27, 2007, 6:29am UTC](https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381/3 "2007-02-27T06:29:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RSL](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@RSL](https://discuss.rubyonrails.org/u/RSL)\
**Post date:** [February 27, 2007, 2:18pm UTC](https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381/4 "2007-02-27T14:18:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discuss.rubyonrails.org/u/Diego)\
**Post date:** [February 27, 2007, 11:51pm UTC](https://discuss.rubyonrails.org/t/change-default-validation-error-messages/9381/5 "2007-02-27T23:51:39Z")

</div>

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