Skip to content

Instantly share code, notes, and snippets.

@coryf
Created May 23, 2014 15:38
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 coryf/e63385ce0065cd411b7c to your computer and use it in GitHub Desktop.
Save coryf/e63385ce0065cd411b7c to your computer and use it in GitHub Desktop.
Bootstrap alert Rails helpers
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 = "&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