Skip to content

Instantly share code, notes, and snippets.

@rorlab
Last active August 29, 2015 14:07
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 rorlab/b8b2ca966867d5839bdf to your computer and use it in GitHub Desktop.
Save rorlab/b8b2ca966867d5839bdf to your computer and use it in GitHub Desktop.
bootstrap alert helper method
module ApplicationHelper
def flash_class(level)
case level
when :notice then "info"
when :success then "success"
when :error then "danger"
when :alert then "warning"
# else "info"
end
end
def alert_box(kind="warning", message="Warnings occurred")
flash_kind = flash_class(kind.to_sym)
content_tag(:div, class:"alert alert-#{flash_kind} alert-dismissible", role: "alert") do
concat(content_tag(:button, type: 'button', class: 'close', data: {dismiss: 'alert'}) do
concat content_tag(:span, raw('×'), "aria-hidden"=>"true")
concat content_tag(:span, "Close", class:"sr-only")
end)
concat fa_icon('info-circle')
concat " "
concat content_tag(:strong, kind.capitalize + '!')
concat " "
concat message
end
end
def flash_box(flash_hash)
capture do
flash_hash.map do | key, value |
concat alert_box(key, value)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment