LoginSignup
0
0

bootstrapのダウンロードの仕方

Posted at

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

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