2009-11-05 17 views
0

我有一个使用低级别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 %> 
+0

让我们看看你的form_for和form.error_messages视图代码。 –

+0

我刚刚添加了代码 – tsdbrown

回答

0

问题是部分形式的简单错字。我应该张贴所有有问题的代码,我敢肯定,如果我做BJ克拉克或其他人会很容易地发现了愚蠢的错误我犯了

课学到的东西!

4

更可能的是你的问题是:

  1. 你是不是传递的form_for正确的选项。
  2. 您正在重定向到表单而不是呈现。
  3. 你不使用的form_for建设者(即text_field_tag而不是f.text_field)

然而,如果没有可以发布您的全控制器/视图,我基本上只是猜测。

+0

感谢您的回答,并对不起,我没有发布足够让你真正看到问题。 – tsdbrown