2010-06-05 30 views
1

注意以下结果时,我提交空白:标题和:描述字段fieldWithErrors未包装的每个错误的领域

Error div tags only wraps the title text field and not the description text area. http://www.freeimagehosting.net/uploads/c14b4a2d74.png

的验证是在控制器:

class Question < ActiveRecord::Base 
    validates_presence_of :title 
    validates_presence_of :description 

而且,形式用这些名称生成:

-form_for(@question) do |f| 
    = f.error_messages 
    = f.label :title 
    = f.text_field :title, :size => 50, :onchange => remote_function(:url => {:action => :display_tag_suggestions}, :with => 'Form.Element.serialize(this)') 
    #suggestions 
    = f.label :description 
    = f.text_area :description 
    ... 

但是,出于某种原因,只有:标题被包裹在错误的div标签中:

<form action="/questions" class="new_question" id="new_question" method="post"> 
    <div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="6HQaiu1D0gBQcKw2pLeZP6Jvn0FSClPD5Sk9HwegzPg=" /></div> 
    <div class="errorExplanation" id="errorExplanation"> 
    <h2>2 errors prohibited this question from being saved</h2> 
    <p>There were problems with the following fields:</p> 
    <ul> 
     <li>Title can't be blank</li> 
     <li>Description can't be blank</li> 
    </ul> 
    </div> 
    <label for="question_title">Title</label> 
    <div class="fieldWithErrors"><input id="question_title" name="question[title]" onchange="new Ajax.Request('/questions/display_tag_suggestions', {asynchronous:true, evalScripts:true, parameters:Form.Element.serialize(this) + '&amp;authenticity_token=' + encodeURIComponent('6HQaiu1D0gBQcKw2pLeZP6Jvn0FSClPD5Sk9HwegzPg=')})" size="50" type="text" value="" /></div> 
    <label for="question_description">Description</label> 
    <textarea cols="40" id="question_description" name="question[description]" rows="20"></textarea> 
    ... 

我不认为这种行为是预期的。大多数人所面临的问题是它用div包装东西,这将无法正确显示。我的问题是,字段不是用div来包装开始的!

我还没有做出任何(有意识的)如何处理错误的变化,所以我不知道为什么它不能正常工作。

+0

在所有其他样式表之后添加scaffold.css – Salil 2010-06-05 04:21:11

+0

我只使用一个样式表,并且我已经尝试将scaffold.css的内容添加到它。但是这并不能解决问题。 div不包装描述html标签。 – user5243421 2010-06-05 09:02:20

回答

1

你使用的是什么版本的Haml?一些旧版本的兼容性错误包装错误。

+0

我使用Haml v2.2.23 – user5243421 2010-06-06 04:59:13

+0

你已经过时了。升级到3.0.9,希望这应该消失。 – 2010-06-07 00:44:06