I have a model that uses the low level validate_on_create
method, based on a simple condition I'm adding an error message to the field, e.g
self.errors.add(:expiry_date, "is too soon") if self.expiry_date && self.expiry_date < Date.today + 1.week
When rendering the view 'new' after a failed save the field isn't picked up by error_messages_for
as I would expect. The error is shown in the ususal list of errors that indicated the validation is working correctly.
Has anybody got any idea why this is? I guess form.error_messages
isn't looking at all errors on the object?
Added the requested code:
<% form_for([:solicitor, @policy]) do |form| %>
<%= form.error_messages :message => "See the list of reasons below to find out why not:", :header_message => "Sorry but we cannot yet create your policy based on the information you've provided." %>
<%= render :partial => 'form', :locals => {:form => form} %>
<% end %>