Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Forked from potomak/_flash.html.erb
Created January 17, 2012 18:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seyhunak/1628032 to your computer and use it in GitHub Desktop.
Save seyhunak/1628032 to your computer and use it in GitHub Desktop.
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] %>
</div>
<% end %>
<% end %>
module ApplicationHelper
def flash_class(level)
case level
when :notice then "info"
when :error then "error"
when :alert then "warning"
end
end
end
@dennysfredericci
Copy link

remember... add a locals in your render partial

<%= render :partial => 'flash', :locals => {:flash => flash} %>

otherwise

undefined method `[]' for nil:NilClass

@bithavoc
Copy link

I think it would be <div class="alert alert-<%= flash_class(level) %>"> instead.

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