gemをインストール
gemfileに以下を記載
gem 'bootstrap', '~> 5.3.0'
bundle installする(コンテナ内で行う場合)
docker compose run web bundle install
共通ファイル作成
flashメッセージは複数のビューファイルで使うので、部分テンプレートにしておく。
views/shared/_flash.html.erb
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>">
<%= message %>
</div>
<% end %>
application.html.erbで読み込みが出来るようにする
<%= render 'shared/flash_message' %>
<%= yield %>
bootstrap対応して色をつける
flashはデフォルトで notice と alert の二種類のキーしか設定できないので、設定を追加する。
application_controller.rb
add_flash_types :success, :info, :warning, :danger
あとはこちらを参照
https://pikawaka.com/rails/flash