NathanTempelman
NathanTempelman

Reputation: 1387

Embed strings in html in rails

I'm trying to make rails' flash messages style with bootstrap 3.

In this piece of code,

    <% flash.each do |key, value| %>
      <div class="alert alert-<%= key %>"><%= value %></div>
    <% end %>

<%=key> puts the key into the class tag like you'd expect. But when I change the middle line to this

<div class="<%= flash_class(key) %>"><%= value %></div>

<%= flash_class(key)%> doesn't embed anything.

flash_class() is in application_helper.rb which is automatically included in views (right?) and it returns a string. I think it's probably something stupid I'm missing, why does this not work?

edit- here's the implementation of flash_class

   def flash_class(level)
        case level
            when :notice then "alert alert-info"
            when :success then "alert alert-success"
            when :error then "alert alert-error"
            when :alert then "alert alert-error"
        end
    end

Upvotes: 2

Views: 106

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54882

Probably a problem comparing string with symbols:

def flash_class(level)
  case level.to_sym

Should solve your problem

Upvotes: 2

Related Questions