Skip to content

Instantly share code, notes, and snippets.

@binarymason
Forked from roberto/_flash_messages.html.erb
Last active March 12, 2016 19:15
Show Gist options
  • Save binarymason/6c7301ce1da4f0f08b40 to your computer and use it in GitHub Desktop.
Save binarymason/6c7301ce1da4f0f08b40 to your computer and use it in GitHub Desktop.
Rails flash messages using Twitter Bootstrap
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
<%= render partial: "shared/flash_messages", flash: flash %>
module ApplicationHelper
def bootstrap_class_for(flash_type)
case flash_type
when "success" then "alert-success" # Green
when "error" then "alert-danger" # Red
when "alert" then "alert-warning" # Yellow
when "notice" then "alert-info" # Blue
else flash_type.to_s
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment