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!
There are the quotes that you want around the class definition in the HTML, and the quotes that delimit the strings called within the ruby code. The ruby inside of the
<%=calls two functions that output strings (cycle, and your methodrow_class) which you want separated by a space. I think either of these will do what you want:or perhaps a little prettier
or even %Q|| format to avoid delimiter confusion…
resulting in something like
EDIT: My original post was wrong. Need to concatenate space between the cycle and row_class method.