Bootstrap 4 alerts with rails 4.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '×'.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