Last active
August 29, 2015 14:07
-
-
Save rorlab/b8b2ca966867d5839bdf to your computer and use it in GitHub Desktop.
bootstrap alert helper method
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 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