Skip to content

Instantly share code, notes, and snippets.

@gbalbuena
Forked from roberto/_flash_messages.html.erb
Last active August 29, 2015 13:56
Show Gist options
  • Save gbalbuena/9023136 to your computer and use it in GitHub Desktop.
Save gbalbuena/9023136 to your computer and use it in GitHub Desktop.
Code to show flash messages with the look and feel of bootstrap 3
<%# shared/_flash_messages.html.erb %>
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<i class='<%= bootstrap_icon_for(type) %>'></i> <%= message %>
</div>
<% end %>
<%= render partial: "shared/flash_messages", flash: flash %>
module ApplicationHelper
def bootstrap_class_for flash_type
case flash_type
when :success
"alert-success"
when :error
"alert-danger"
when :alert
"alert-warning"
when :notice
"alert-info"
else
flash_type.to_s
end
end
def bootstrap_icon_for flash_type
case flash_type
when :success
"glyphicon glyphicon-ok-circle"
when :error
"glyphicon glyphicon-remove-circle"
when :alert
"glyphicon glyphicon-warning-sign"
when :notice
"glyphicon glyphicon-exclamation-sign"
else
"glyphicon glyphicon-question-sign"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment