我有一个使用低级别validate_on_create
方法的模型,基于一个简单的条件,我将错误信息传送到现场,如的Rails:form.error_messages不以fieldWithErrors包装定制验证领域的div
self.errors.add(:expiry_date, "is too soon") if self.expiry_date && self.expiry_date < Date.today + 1.week
当渲染视图“新”失败后,救场不被error_messages_for
拿起我期望的那样。错误显示在错误的ususal列表中,表明验证工作正常。
有没有人知道这是为什么?我猜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视图代码。 –
我刚刚添加了代码 – tsdbrown