There are no load classes in the Flash post
I have a view where I want to display a flash message for some events. I can see the flash message, but not in color as it should be with bootstrap. like green for success, blue for notification, etc., but I see everything in white.
Here is my code:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, class: name %>
<% end %>
PS: this is not complete code, just a snippet of code to give an idea, other bootstrap classes work, but here, other than the post on the ugly white background, I get nothing. Any suggestions?
+3
source to share
2 answers
You can use a helper method to assign the correct bootstrap classes according to the notification type flash
:
def alert_for(flash_type)
{
success: 'alert-success',
error: 'alert-danger',
alert: 'alert-warning',
notice: 'alert-info'
}[flash_type.to_sym] || flash_type.to_s
end
And then use it like:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, class: [:alert, alert_for(name)]%>
<% end %>
+7
source to share