0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rails flashのパーシャルの書き方

0
Last updated at Posted at 2026-08-18

はじめに

私は何度フラッシュメッセージのパーシャルを書いても忘れてしまうので、ここで備忘録として残しておきます。

手順

_flash.html.haml
- flash.each do |key, value|
  - alert_class = { notice: 'alert-success', alert: 'alert-danger'}.fetch(key.to_sym, 'alert-danger')
  .alert{ class: alert_class}
    = value

終わり

Qiitaで残しておけばいつでも取ってこれるので便利ですね。
今後フラッシュメッセージを作ろうとする誰かの役に立てられれば光栄です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?