フラッシュメッセージの設定
まずコントローラーに表示したいメッセージを記述
例
flash[:notice] = "ログインしました"
flash.now[:aleart] = "ログアウトしました"
次にviewにflashを表示させる
<%= flash[:notice] %>
これだけでflashメッセージは表示されます。
でも毎回<%= flash[:notice] %>と書くのは面倒なので部分テンプレートを使用する
Bootstrapを使用していい感じに表示する
まずapplication_controller.rbにadd_flash_typesメソッドを使用してBootstrapに対応したsuccess info danger warningを使用でできるようにする
add_flash_types :success, :info, :warning, :danger
次にviewsにsharedフォルダを作成
フォルダの中に_flash_messages_html.erbを作成
<div class='alert alert-<%= message_type%>'><%= message %></div>
<% end %>
あとはlayouts/application.html.erbのbodyの中に
<%= render 'shared_flash_message' %>
を追加したら実装完了です。