Assign multiple css classes to a table element in Rails

Posted by Eric K on Stack Overflow See other posts from Stack Overflow or by Eric K
Published on 2012-03-26T16:16:43Z Indexed on 2012/03/26 17:29 UTC
Read the original article Hit count: 175

I'm trying to style a table row using both cycle and a helper, like shown:

<tr class= <%= cycle("list-line-odd #{row_class(item)}", "list-line-even #{row_class(item)}")%> >

However, when I do this, the resulting HTML is:

<tr class = "list-line-odd" lowest-price>

with the return from the helper method not enclosed in the quotes, and therefore not recognized.

Here's the helper I'm using:

  def row_class(item)
    if item.highest_price > 0 and item.lowest_price > 0 and item.highest_price != item.lowest_price
      if item.current_price >= item.highest_price
        "highest-price"
      elsif item.current_price <= item.lowest_price
        "lowest-price"
      end
    end
  end

I must be missing something obvious, but I just can't figure out how to wrap both the result of cycle and the helper method return in the same set of quotes. Any help would be greatly appreciated!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about css