Created
December 17, 2018 16:19
-
-
Save TechFounder/5bfd306b26ccd4afcf95403cd8b0b75c to your computer and use it in GitHub Desktop.
Rails flash message using bootstrap styling - underneath navbar, full width
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
<%= render 'layouts/navbar' %> | |
# Put this flash message block between the navbar and the yield | |
<% flash.each do |name, msg| %> | |
<% unless flash_blacklist(name) %> | |
<%= content_tag(:div, class: flash_class(name)) do %> | |
<%= msg %> | |
<button type="button" class="close" data-dismiss="alert">×</button> | |
<% end %> | |
<% end %> | |
<% end %> | |
<%= yield %> |
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
# This will assign the correct bootstrap colors to the messages | |
def flash_class(name) | |
case name | |
when 'notice' then 'alert alert-info alert-dismissable fade show' | |
when 'success' then 'alert alert-success alert-dismissable fade show' | |
when 'error' then 'alert alert-danger alert-dismissable fade show' | |
when 'alert' then 'alert alert-danger alert-dismissable fade show' | |
else | |
'alert alert-primary alert-dismissable fade show' | |
end | |
end | |
# Exlude these messages from appearing | |
def flash_blacklist(name) | |
%w(timedout).include?(name) | |
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
# Flash message timer & slider | |
$(document).on 'turbolinks:load', -> | |
$('.alert').delay(4000).slideUp 500, -> | |
$('.alert').alert 'close' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment