Skip to content

Instantly share code, notes, and snippets.

@jameslafa
Created December 16, 2015 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameslafa/e7e38deb238938037bc2 to your computer and use it in GitHub Desktop.
Save jameslafa/e7e38deb238938037bc2 to your computer and use it in GitHub Desktop.
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 %>
</div>
</div>
<% 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
end
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
end)
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment