# Custom validation error messages

**URL:** <https://www.ruby-forum.com/t/custom-validation-error-messages/103671>\
**Category:** Rails\
**Created:** [May 9, 2007, 3:46am UTC](https://www.ruby-forum.com/t/custom-validation-error-messages/103671 "2007-05-09T03:46:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [May 9, 2007, 3:46am UTC](https://www.ruby-forum.com/t/custom-validation-error-messages/103671/1 "2007-05-09T03:46:22Z")

</div>

Hi all,

I have a few questions regarding the error messages which are produced  
by default. For example, if I have “validates\_uniqueness\_of” I may get  
an error message "Surname has already been taken’

What if I want a custom message without prefixing the attribute name?  
I’ve come across a plugin which allows me to do this:

validates\_uniqueness\_of :name, :message =\> ‘^The surname supplied is  
not valid.’

Whereby the use of the ^ says that error message should be output as  
is, without any prefixing, but just without the ^.

Are there any other cleaner alternatives than this plugin? What if  
(and most likely it may) the Rails full\_messages changes and things  
then break? BTW full\_messages is overriden by said plugin. I know it’s  
probably being picky of me, and the plugin is almost there and a clean  
enough solution.

Thought I’d ask.

Cheers,  
Diego

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [May 9, 2007, 4:41am UTC](https://www.ruby-forum.com/t/custom-validation-error-messages/103671/2 "2007-05-09T04:41:06Z")

</div>

Hey Diego, I believe you’re talking about the plugin I wrote,  
[http://rubyforge.org/projects/railserrorsfor/](http://rubyforge.org/projects/railserrorsfor/), which, by the way, is now  
a gem, and I would definitely recommend using that.

I don’t override any Rails methods, exept for error\_messages\_for, so if  
you’re worried about how things like full\_messages work, don’t worry,  
they’re safe.

I use this gem in all my Rails projects, so you can rest assured that  
I’m constantly keeping it up-to-date, and as bug free as a I can,  
because I need it.

All you need to do is install the gem, and require it, and you’re done.  
There are other great parts to this gem as well, like the ability to  
have multiple object errors printed out in the same errors ‘box’, as  
well as the ability to specify the partial you would like to use to  
format the errors.

Let me know if you find any bugs, or have any features you would like to  
add, I’m all ears!

Good luck!
