# Easy custom validation messages on a per-attribute basis

**URL:** <https://www.ruby-forum.com/t/easy-custom-validation-messages-on-a-per-attribute-basis/188970>\
**Category:** Rails\
**Created:** [May 21, 2010, 9:15am UTC](https://www.ruby-forum.com/t/easy-custom-validation-messages-on-a-per-attribute-basis/188970 "2010-05-21T09:15:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@marcelo](https://www.ruby-forum.com/u/marcelo)\
**Post date:** [May 21, 2010, 9:15am UTC](https://www.ruby-forum.com/t/easy-custom-validation-messages-on-a-per-attribute-basis/188970/1 "2010-05-21T09:15:50Z")

</div>

When i do this:

validates\_presence\_of :name, :email, :message =\> “Can’t be blank”

and use the “error\_message\_on” method in my view, i get the same  
message for both “name” and “email” fields - Can’t be blank.

How do i specify a different message for each attribute without having  
to write a custom validation message?

Passing a hash to the :message parameter would be great but it doesn’t  
work:

validates\_presence\_of :name, :email, :message =\>{:name =\> ‘name  
message’, :email =\> ‘email message’}

Any thoughts?

---

<div class="post-metadata">

**Author:** ![marcelo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@marcelo](https://www.ruby-forum.com/u/marcelo)\
**Post date:** [May 21, 2010, 3:26pm UTC](https://www.ruby-forum.com/t/easy-custom-validation-messages-on-a-per-attribute-basis/188970/2 "2010-05-21T15:26:25Z")

</div>

You’ll have to separate you attributes:

validates\_presence\_of :name, :message =\> “Your name error here”  
validates\_presence\_of :email, :message =\> “Your e-mail error here”
