はじめに
form
で入力に誤り(例えば無入力)があるとエラーメッセージを表示させるためにerrorsメソッド
を用いて記述し、動きを確認するとビューが崩れるという問題が発生しました。その時の自分の解決した方法です。
原因
崩れたビューを確認するとfield_with_errors
というdivクラス
が付与させていていることを確認した。これが原因である。
対処
今回はこのfield_with_errors
というdivクラス
が付与されないようにした。
config/application.rb
に以下の記述をした。
module #モデル名
class Application < Rails::Application
config.load_defaults 6.0
config.i18n.default_locale = :ja
config.action_view.field_error_proc = Proc.new { |html_tag, instance| html_tag }
#↑この記述をプラスした
end
end
こうすることで余計なクラスが付与されずにできました!