I have an view where I want to display flash message for some events. I can see the flash message but not in color as it should with bootstrap. for example green for success, blue for notice etc. but I see everything in white.
Here is my code:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, class: name %>
<% end %>
PS: it is not full code, just code snippet to give idea, other bootstrap classes are working but here except message in ugly white background I do not get anything. Any suggestions?
You can use a helper method for assigning proper bootstrap classes according to the type of flash notification messages:
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 as:
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, class: [:alert, alert_for(name)]%>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With