Created
May 23, 2014 15:38
-
-
Save coryf/e63385ce0065cd411b7c to your computer and use it in GitHub Desktop.
Bootstrap alert Rails helpers
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
def bootstrap_alert(type, message, options = {}) | |
options.reverse_merge!(dismissable: true) | |
classes = %w(alert) | |
classes << case type | |
when :error, :alert | |
'alert-danger' | |
else | |
'alert-info' | |
end | |
if options[:dismissable] | |
classes << '.alert-dismissable' | |
times = "×".html_safe | |
button_options = { | |
type: :button, | |
class: 'close', | |
data: { dismiss: "alert" }, | |
"aria-hidden" => true, | |
} | |
message = capture do | |
concat content_tag(:button, times, button_options) | |
concat message | |
end | |
end | |
content_tag(:div, message, class: classes) | |
end | |
def flash_messages | |
capture do | |
flash.each do |type, message| | |
concat bootstrap_alert(type, message) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment