Skip to content

Instantly share code, notes, and snippets.

@basicavisual
Forked from suryart/application.html.erb
Created March 16, 2018 00:14
Show Gist options
  • Save basicavisual/90c5e52a697359b51cc1f95c208af2e9 to your computer and use it in GitHub Desktop.
Save basicavisual/90c5e52a697359b51cc1f95c208af2e9 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). An improved version of https://gist.github.com/roberto/3344628
// layout file
<body>
<div class="container">
<%= flash_messages %>
<%= yield %>
</div><!-- /container -->
</body>
module ApplicationHelper
def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || 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)} fade in") do
concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' })
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