Skip to content

Instantly share code, notes, and snippets.

@jCrip
Created February 15, 2015 22:08
Show Gist options
  • Save jCrip/39ec747fe64527053556 to your computer and use it in GitHub Desktop.
Save jCrip/39ec747fe64527053556 to your computer and use it in GitHub Desktop.
Rails 4 flash messages using Twitter Bootstrap(bootstrap-sass: https://github.com/thomas-mcdonald/bootstrap-sass).
module ApplicationHelper
def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type.to_sym] || flash_type.to_s
end
def flash_messages(opts = {})
flash.each do |msg_type, message|
concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do
concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }) do
concat content_tag(:span, '×'.html_safe, 'aria-hidden' => true)
concat content_tag(:span, 'Close', class: 'sr-only')
end)
concat message
end)
end
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment