Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2015 15:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Bootstrap 4 alerts with rails 4.2
<% if flash.any? %>
<div class="row flashes">
<div class="col-md-8 col-md-offset-2">
<% flash.each do |msg_type, message| %>
<%= flash_message(msg_type, message) %>
<% end %>
<% end %>
module ApplicationHelper
def bootstrap_alert_class_for(flash_type)
{success: "alert-success",
error: "alert-danger",
alert: "alert-warning",
notice: "alert-info"
}[flash_type.to_sym] || flash_type.to_s
def flash_message(msg_type, message)
concat(content_tag(:div, message, class: "alert #{bootstrap_alert_class_for(msg_type)} alert-dismissible fade in", role: "alert") do
concat content_tag(:button, '&times;'.html_safe, class: "close", data: {dismiss: 'alert'}, 'aria-label': "Close")
concat message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment