So what I am trying to do is to apply a different class to the div containing the flash message depending on the type of flash message (i.e. error, notice, etc.).
I have this in my application.html.erb:
<%- flash.each do |name, msg| -%>
<% if name = "error" %>
<%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message error" %>
<% elsif name = "notice" %>
<%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message success" %>
<% elsif name = "warning" %>
<%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message warning" %>
<% end %>
<%- end -%>
But, it is always outputting a div with id=flash_error.
Why is that?
Update 1:
If I change the equality checks to be ==, it seems to completely skip over that portion of the if statement.
<%- flash.each do |name, msg| -%>
<% if name == "error" %>
<%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message error" %>
<% elsif name = "notice" %>
<%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message success" %>
<% elsif name == "warning" %>
<%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message warning" %>
<% end %>
<%- end -%>
If you notice, in the code above, I have == in for error and warning and I have = for notice. Well, in this case it actually outputs the notice div like I want it to. It seems that when I do a check for ="error" it exits the conditional altogether, regardless of whether or not the check was right. But once I add == it doesn’t even do the check it seems. Very bizarre!
Could it be because you are not checking for equality?
Not a check for equality
A check for equality
It could also be that you are checking for a string. The flash hash is indexed by symbols.
Try