Is there any (simple) way to get some control of the order in which a model's errors appear in the view? Ordering the rules does not seem to help whatsoever.
+2
A:
Use error_message_on
instead of error_messages
to get the message for an individual attribute.
<div class="errorMessages">
<% %{name title description}.each do |att| %>
<%= f.error_message_on att, :css_class => "error" %>
<% end %>
</div>
Baldu
2009-10-25 15:29:32
Perfect. That's what I needed.
Yar
2009-10-25 18:28:55
A:
Here's an answer (for my own notes, basically) using Baldu's answer. This puts the attribute_names in alpha order:
<% if @model.errors.length>0 %>
<div class="errorExplanation">
<h3>There were problems with the following fields:</h3><ul>
<% @model.attribute_names.each do |attribute| %>
<% if [email protected][attribute].blank? %>
<li><%= f.error_message_on attribute, Model.human_attribute_name(attribute)+ " ", :style=>"display:inline" %></li>
<% end %>
</ul>
<% end %>
</div>
<% end %>
Of course you can parametrize this further as a partial, for instance. I'll probably do that :)
Yar
2009-10-26 23:22:34
A:
In 2.3.6 validation messages will show in order you declared them in code
Adrian Serafin
2009-12-23 10:02:39