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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:
<ul>
<% @post.errors.each_full do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
in your view- more on this <a href="http://wiki.rubyonrails.org/rails/
pages/HowtoValidate" title="here">here</a>.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---