Skip to content

Instantly share code, notes, and snippets.

@squiter
Forked from potomak/_flash.html.erb
Last active June 8, 2018 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squiter/5665815 to your computer and use it in GitHub Desktop.
Save squiter/5665815 to your computer and use it in GitHub Desktop.
Little snippet to render flash messages using twitter bootstrap in Rails.
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert <%= 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 "alert-info"
when :error then "alert-error"
when :alert then "alert-warning"
end
end
end
@sapienza
Copy link

Nice!

@carlosvazquez
Copy link

Works perfect, thank you!

@NazarK
Copy link

NazarK commented Jun 8, 2018

all inside view version (haml):

- flash_class = {notice: 'alert-info', error: 'alert-error', alert: 'alert-info'}
- [:notice, :error, :alert].each do |level|
  - unless flash[level].blank?
    %div{:class => "alert #{flash_class[level]}"}
      %a.close{:href => "#"} ×
      = content_tag :p, flash[level]

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