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 %>
<% @object.errors.messages.values.flatten.each do |error| %> <li><%= error %></li> <% end %>This worked for us (Rails 4):
<% resource.errors.each do |attr,msg| %>
<li><%= msg %></li>
<% end %>
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