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.


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.