Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing field name from validation error message [duplicate]

Tags:

in rails 3 i don't want to show field names in error messages. Anyone know how to do that ?

validates_presence_of :title, :message => "no title" 

it shows

Title no title  

i want

no title 
like image 926
hakaooa Avatar asked Mar 21 '11 08:03

hakaooa


2 Answers

In your form view change your current code

      <%@object.errors.full_messages.each do |msg| %>         <li><%= msg %></li>       <% end %> 

With this

      <%@object.errors.messages.values.each do |msg| %>         <%msg.each do  |m| %>           <li><%= m %></li>         <%end %>       <% end %> 
like image 175
Erick Eduardo Garcia Avatar answered Sep 19 '22 14:09

Erick Eduardo Garcia


This worked for us (Rails 4):

<% resource.errors.each do |attr,msg| %>     <li><%= msg %></li> <% end %> 
like image 27
Richard Peck Avatar answered Sep 20 '22 14:09

Richard Peck