Skip to content

Instantly share code, notes, and snippets.

@pawelztef
Last active August 9, 2021 02:16
Show Gist options
  • Save pawelztef/f9a821695e58ec685463be7bf691da70 to your computer and use it in GitHub Desktop.
Save pawelztef/f9a821695e58ec685463be7bf691da70 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