# Custom errors for validates\_presence, etc

**URL:** <https://www.ruby-forum.com/t/custom-errors-for-validates-presence-etc/106414>\
**Category:** Rails\
**Created:** [June 10, 2007, 4:47am UTC](https://www.ruby-forum.com/t/custom-errors-for-validates-presence-etc/106414 "2007-06-10T04:47:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [June 10, 2007, 4:47am UTC](https://www.ruby-forum.com/t/custom-errors-for-validates-presence-etc/106414/1 "2007-06-10T04:47:38Z")

</div>

I am trying to figure out how to customize the error messages when I use  
validates\_presence\_of. I am validating a user name and I use \<%=  
error\_messages\_for ‘user’ %\> in my view to display the messages. I know  
you can customize in the model with :message =\>‘custom message’, but I  
am trying to get rid of the first part of the error message which is,

1 error prohibited this user from being saved  
There were problems with the following fields:

Is there any way to do this or is it hard coded into the rails code?

---

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [June 21, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/custom-errors-for-validates-presence-etc/106414/2 "2007-06-21T20:56:26Z")

</div>

I’m struggling with the same right now.  
Does anybody know how to do this?  
Thanks.

Sabon

---

<div class="post-metadata">

**Author:** ![yannimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/7993a0/32.png) [@yannimac](https://www.ruby-forum.com/u/yannimac)\
**Post date:** [June 21, 2007, 10:08pm UTC](https://www.ruby-forum.com/t/custom-errors-for-validates-presence-etc/106414/3 "2007-06-21T22:08:36Z")

</div>

On 6/9/07, Yanni M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there any way to do this or is it hard coded into the rails code?  
> The basic idea is to look at the source for error\_messages\_for and  
> then drop your own replacement into app/helpers/application\_helper.rb.

Here’s a _real_ simple example:

def error\_messages\_for(object\_name)  
object = instance\_variable\_get(“@#{object\_name}”)  
return ‘’ if object.errors.empty?  
content\_tag(‘ul’, object.errors.full\_messages.collect {|msg|  
content\_tag(‘li’, msg)},  
{ :class =\> ‘error’ })  
end
