舉個例子,在表單中有這樣的內容:
<dl>
<dt>
<%= f.label :subject %>
</dt>
<dd>
<%= f.text_field :subject %>
</dd>
</dl>
在瀏覽器中顯示成:
■Subject
(※注:■由CSS生成)
如果對表單進行驗證,驗證後再顯示的格式就亂了,變成這樣:
■
Subject
為什麼會錯位呢?
You should override
ActionView::Base.field_error_proc
. It's currently defined as this withinActionView::Base
:You can override it by putting this in your application's class inside
config/application.rb
:Restart rails server for this change to take effect.
(全文抄襲自 http://stackoverflow.com/questions/5267998/rails-3-field-with-errors-wrapper-changes-the-page-appearance-how-to-avoid-t)
當然,更推薦改成這樣