注意以下結果時,我提交空白:標題和:描述字段fieldWithErrors未包裝的每個錯誤的領域
的驗證是在控制器:
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) + '&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來包裝開始的!
我還沒有做出任何(有意識的)如何處理錯誤的變化,所以我不知道爲什麼它不能正常工作。
在所有其他樣式表之後添加scaffold.css – Salil 2010-06-05 04:21:11
我只使用一個樣式表,並且我已經嘗試將scaffold.css的內容添加到它。但是這並不能解決問題。 div不包裝描述html標籤。 – user5243421 2010-06-05 09:02:20