0
0

More than 3 years have passed since last update.

form_forで自動生成される<div class="field_with_error">を消す方法

Posted at

formへの入力でバリデーションエラーがあると自動生成される。

生成される位置


<form>
 <input type="hidden">
 <input type="hidden">
 <div class="field_with_error">
  <input type="text">
 </div>
//以下略

でこいつの厄介なところはレイアウトに影響してくるというところで、

これを

スクリーンショット 2019-12-27 18.22.40.png

こんな風に崩してくる。

スクリーンショット 2019-12-27 18.22.22.png

で対処法を調べていたら

config/application.rb

module ChatSpace
  class Application < Rails::Application
    config.generators do |g|
    #中略
  end

ここに

config/application.rb

module ChatSpace
  class Application < Rails::Application
    config.generators do |g|
    #中略
    config.action_view.field_error_proc = Proc.new { |html_tag, instance| html_tag }

  end

これを記述すれば自動生成されなくなってレイアウト崩れも解決されます。

0
0
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
0
0