Skip to content

Instantly share code, notes, and snippets.

@mihir-kumar-thakur
Forked from pawelztef/_flash.html.erb
Created September 22, 2019 06:22
Show Gist options
  • Save mihir-kumar-thakur/c4e497e7ad4f1d05c374b1c3b17198fd to your computer and use it in GitHub Desktop.
Save mihir-kumar-thakur/c4e497e7ad4f1d05c374b1c3b17198fd to your computer and use it in GitHub Desktop.
rails flash messages with bootstrap 4
<div class="container">
<% flash.each do |type, msg| %>
<div class="alert <%= bootstrap_class_for_flash(type) %> alert-dismissable fade show">
<%= msg %>
<button class="close" data-dismiss="alert">x</button>
</div>
<% end %>
</div>
<%= render partial: 'flash', flash: flash %>
module ApplicationHelper
def bootstrap_class_for_flash(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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment