:message

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs