2

I realise there are many questions on this already but I can't find one with a solution to this issue.

I have a custom message set with my validation rule like this:

validates :grace, :inclusion => { :in => 1..7, :message => " should be between 1 and 7" }

and the validation error message will be

"Grace should be between 1 and 7"

but I don't want it to automatically use the name Grace as I want it to say Cancellation Period - so my question is how do I override this default behaviour?

EDIT

Here's my view code to display errors

<% if @object.errors.any? %>
  <% @object.errors.full_messages.each do |msg| %>
    <p class="error"><%= msg %></p>
  <% end %>
<% end %>
tommyd456
  • 10,443
  • 26
  • 89
  • 163
  • That behaviour is down to the view rather than the model, post the code that outputs the error messages. Also, try it in the console and see what the error actually is. – Matt Sep 18 '13 at 15:23
  • added view code but surely need to manipulate the message before it gets to the view? – tommyd456 Sep 18 '13 at 15:29
  • 2
    I believe this solution should work for you. http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails – makewavesnotwar Sep 18 '13 at 15:34
  • I spotted that earlier and didn't realise it was what I needed - thanks for that – tommyd456 Sep 18 '13 at 15:48

0 Answers0