【发布时间】:2009-11-05 16:51:24
【问题描述】:
我有一个使用低级别 validate_on_create 方法的模型,基于一个简单的条件,我在字段中添加了一条错误消息,例如
self.errors.add(:expiry_date, "is too soon") if self.expiry_date && self.expiry_date < Date.today + 1.week
在保存失败后呈现“新”视图时,error_messages_for 没有像我预期的那样拾取该字段。该错误显示在通常的错误列表中,表明验证工作正常。
有人知道这是为什么吗?我猜form.error_messages 没有查看对象上的所有错误?
添加了请求的代码:
<% 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 %>
【问题讨论】:
-
让我们看看你的form_for和form.error_messages查看代码。
-
我刚刚添加了代码
标签: ruby-on-rails validation activerecord