LoginSignup
17
16

More than 5 years have passed since last update.

railsのValidationで<div>がぶっ込まれてスタイルが崩れたら

Last updated at Posted at 2012-07-26

ActionView::Base.field_error_procをオーバーライドする

rails2系なら
config/environment.rbに追加

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|  %(<span class="fieldWithErrors">#{html_tag}</span>)} 

rails3系なら
config/application.rbに追加

config.action_view.field_error_proc = Proc.new { |html_tag, instance| "<span class='field_with_errors'>#{html_tag}</span>".html_safe }

3系はhtml_safe指定しないとタグがescapeされるので

17
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
16