validation custom message for rails 3 validation custom message for rails 3 ruby ruby

validation custom message for rails 3


Try this

validates :title, presence: { message: "Story title is required" }


Actually, I did this in a better way. If you want to remove the field title from the message you should use this on your _form.htmk.erb view:

As you can see inside this view:

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

Replace it by:

<ul>  <% @article.errors.each_with_index do |msg, i| %>  <li><%= msg[1] %></li>  <% end %></ul>


A custom message for a boolean with conditionals might be:

validates :foo,  inclusion: { in: [true, false], message: "cannot be blank" }, if: :bar?