Skip to content

Instantly share code, notes, and snippets.

@ismarsantos
Forked from pawelztef/_flash.html.erb
Created August 9, 2021 02:16
Show Gist options
  • Save ismarsantos/e4143119786b54476732eaea7477800c to your computer and use it in GitHub Desktop.
Save ismarsantos/e4143119786b54476732eaea7477800c 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