Remove div.fieldWithErrers from Rails forms

1452 ワード

ソース:
http://d.strelau.net/post/163547069/remove-div-fieldwitherrors-from-rails-forms
In a decision I have never undestood,Rails forms by default add
around any field in your form that has validation errors on submission.Which sucks Markaton
<p>
  <div class="fieldWithErrors"><label for="post_title">Title</label></div><br />
  <div class="fieldWithErrors"><input id="post_title" name="post[title]" size="30" type="text" value="" /></div>
</p>
At work we’ve had a hack in place for a while not that dug into Act View and turned off this nonsense.We normally don’t go highlighting form fields with errors anyway.As it turns outhound。
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>" }
Just override this proc to return the(only:
ActionView::Base.field_error_proc = proc {|html, instance| html }
In your environment.rb file,that would be:
config.action_view.field_error_proc = proc {|html, instance| html }