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
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
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 %>
This worked for us (Rails 4):
<% resource.errors.each do |attr,msg| %>
<li><%= msg %></li>
<% end %>
This worked for me in Rails 4 (haml):
%ul
- @some_object.errors.messages.each do |message|
%li= message[1][0]
module ActiveModel
class Errors
def full_messages
map { |attribute, message|
message
}
end
end
end
See also: Change displayed column name in rails
You can use the following Gem
https://github.com/jeremydurham/custom-err-msg
You can use a '^' character at the start of the message value. And it will only show the characters after this.
validates_presence_of :title, :message => "^no title"
You can use the following Gem also
If you change the label of the element it will effect the error message label. So if you change it to a blank string it will render just the message:
-# reviews/_form.html.haml
= form_for review do |form|
= form.label :rating, (review.errors[:rating] ? "" : "Rate this Item" )