44
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsで自動で挿入されるエラー出力タグ <div class="field-with-errors"></div>の変更

Last updated at Posted at 2014-08-29

Railsはエラーがでたフォームの項目に、自動で<div class="field-with-errors"></div>を挿入する。
勝手に挿入されてデザインとか崩れるので、これを変更してみる。

具体的にはconfig.action_view.field_error_procの設定をすることで反映できる。

なにも挿入したくない場合

application.rb
config.action_view.field_error_proc = proc { |html_tag, instance| html_tag }

bootstrapのclassを挿入する

application.rb
config.action_view.field_error_proc = proc { |html_tag, instance| "<div class='has-error'>#{html_tag}</div>".html_safe }
44
43
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
44
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?