Skip to content

Instantly share code, notes, and snippets.

@cwsaylor
Created October 15, 2016 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwsaylor/25faa1b8e42c39c32d97fcccf1c88e6a to your computer and use it in GitHub Desktop.
Save cwsaylor/25faa1b8e42c39c32d97fcccf1c88e6a to your computer and use it in GitHub Desktop.
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