Created
October 15, 2016 04:24
-
-
Save cwsaylor/25faa1b8e42c39c32d97fcccf1c88e6a to your computer and use it in GitHub Desktop.
This file contains 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 FlashHelper | |
ALERT_TYPES = { | |
success: :success, | |
notice: :success, | |
info: :info, | |
warning: :warning, | |
danger: :danger, | |
alert: :danger | |
} | |
def display_flash | |
flash_messages = [] | |
flash.each do |key, message| | |
# Skip empty messages, e.g. for devise messages set to nothing in a locale file. | |
next if message.blank? | |
type = ALERT_TYPES.fetch(key.to_sym, key) | |
Array(message).each do |msg| | |
text = content_tag(:div, | |
content_tag(:button, | |
content_tag(:span, "×".html_safe, "aria-hidden" => "true") + content_tag(:span, "Close", class: "sr-only"), | |
class: "close", data: { dismiss: "alert" }) + msg, | |
class: "alert alert-#{type} alert-dismissible", role: "alert") | |
flash_messages << text if message | |
end | |
end | |
flash_messages.join("\n").html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment