# :message

**URL:** <https://www.ruby-forum.com/t/message/117095>\
**Category:** Rails\
**Created:** [October 12, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/message/117095 "2007-10-12T22:14:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 12, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/message/117095/1 "2007-10-12T22:14:54Z")

</div>

When using the :message symbol in a validation check in one of my  
models, how do you get that message back to the view to be displayed?  
For exmaple:

validates\_uniqueness\_of :card\_num, :scope =\> [:issuing\_company,  
:user\_id], :message =\> ‘Duplicate Card Infmroation Entered’

I would like that error message to be displayed in a div in my app.  
Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 12, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/message/117095/2 "2007-10-12T22:48:03Z")

</div>

The simplest way (but also the least customizable) is to add \<%=  
error\_messages\_for ‘objectname’ %\>

within your view. In your action you need to stick something like  
render :action =\> ‘pagename’ in your controller, where ‘pagename’  
corresponds to the view containing the error message helper.

If/when you need to tweak things slightly, try something like

\<% unless @post.errors.empty? %\>  
The post couldn’t be saved due to these errors:

 \<% @post.errors.each\_full do |message| %\> - \<%= message %\>
 \<% end %\> 
\<% end %\>

in your view- more on this [here](http://wiki.rubyonrails.org/rails/%0Apages/HowtoValidate "here").
