-
-
Save fjahr/b3828b9f4e333e74ba1894687d65e055 to your computer and use it in GitHub Desktop.
Displaying Rails 5 flash messages with Twitter Bootstrap 4 (last tested on Alpha-v6). Updated version of https://gist.github.com/suryart/7418454
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// layout file | |
<body> | |
<div class="container"> | |
<%= flash_messages %> | |
<%= yield %> | |
</div><!-- /container --> | |
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def bootstrap_class_for flash_type | |
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }.stringify_keys[flash_type.to_s] || flash_type.to_s | |
end | |
def flash_messages(opts = {}) | |
flash.each do |msg_type, message| | |
concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)}", role: "alert") do | |
concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' }) | |
concat message | |
end) | |
end | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bootstrap 5
def flash_messages(opts = {})
flash.each do |msg_type, message|
concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible fade show", role: "alert") do
concat content_tag(:button, '', class: "btn-close", data: { bs_dismiss: 'alert' })
concat message
end)
end
nil
end