Skip to content

Instantly share code, notes, and snippets.

Created January 12, 2012 14:35
What would you like to do?
Rails flash messages using Twitter bootstrap
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert-message <%= flash_class(level) %>">
<a class="close" href="#">×</a>
<%= content_tag :p, flash[level] %>
<% end %>
<% end %>
module ApplicationHelper
def flash_class(level)
case level
when :notice then "info"
when :error then "error"
when :alert then "warning"
Copy link

Simbul commented Jul 8, 2012

The class is just called alert (as opposed to alert-message) in Bootstrap 2.

Copy link

dewyze commented Jul 9, 2012

I had an error also found here:

I don't think you can name your partial "_flash.html.erb". It needs to be named something else. Otherwise, thanks! Works great!

Copy link

vishnun commented Apr 30, 2013

Thanks a fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment