Skip to content

Instantly share code, notes, and snippets.

@AquisTech
Created February 25, 2016 16:39
Show Gist options
  • Save AquisTech/5805e1b7589a6e0765fd to your computer and use it in GitHub Desktop.
Save AquisTech/5805e1b7589a6e0765fd to your computer and use it in GitHub Desktop.
Flash Message Helper (Foundation 6)
module FlashMessagesHelper
def render_flash_messages
flash.delete(:timedout) # FIX: https://github.com/plataformatec/devise/issues/1777
safe_join flash.map { |flash_type, message| alert_box(flash_type, message) }
end
private
def close_button(dismiss)
link_to '×'.html_safe, 'javascript:void(0)', class: 'close-button', 'aria-label': 'Dismiss alert', data: { close: '' }
end
def flash_type(type)
{ error: 'alert', alert: 'warning', notice: 'success' }.with_indifferent_access[type]
end
def alert_box(type, message)
content_tag(:div, class: "callout #{flash_type(type)} text-default", data: { closable: '' }) do
(message + close_button(:alert)).html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment