Skip to content

Instantly share code, notes, and snippets.

@cmthakur
Forked from roberto/_flash_messages.html.erb
Last active August 29, 2015 14:18
Show Gist options
  • Save cmthakur/f400d8c191b64e72deb0 to your computer and use it in GitHub Desktop.
Save cmthakur/f400d8c191b64e72deb0 to your computer and use it in GitHub Desktop.
How to add flash message in Rails 4
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> alert-dismissable fade in">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<%= 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" # Green
when :error
"alert-danger" # Red
when :alert
"alert-warning" # Yellow
when :notice
"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