2
我试图同时使用cycle
和一个帮手,像显示样式表行:分配多个CSS类Rails中的表元素
<tr class= <%= cycle("list-line-odd #{row_class(item)}", "list-line-even #{row_class(item)}")%> >
然而,当我这样做,所产生的HTML是:
<tr class = "list-line-odd" lowest-price>
从辅助方法的返回不包含在引号中,因此无法识别。
下面是我使用的帮手:
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
我必须失去了一些东西很明显,但我只是无法弄清楚如何包装循环的两个结果,并在同一个辅助方法返回一套报价。任何帮助将不胜感激!
这个伎俩!因为那看起来最干净,我选择了第二种选择。谢谢您的帮助! – 2012-03-26 18:26:39