In my application.html.erb file, I have:
<div class="container">
<% flash.each do | type, message | %>
<div class="alert <%= flash_class(type) %>">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span></button>
<%= message %>
</div>
<% end %>
<%= yield %>
</div>
I have the flash_class as a helper method:
module ApplicationHelper
def flash_class(type)
case type
when :alert
"alert-error"
when :notice
"alert-success"
else
""
end
end
end
Though what happens is the class isn't being appended in the HTML. When I create an error, the 'alert-error' class isn't added on:
Any ideas why that might be the case?
You might be sending in String
for type instead of Symbol
in the flash_class
method.
An easy fix would be calling type.to_sym
in the flash_class
helper method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.