Assign multiple css classes to a table element in Rails
- by Eric K
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!