I have a column in my HTML table with negative and positive numbers. If the number is negative, I display a green arrow next to the number. If it’s positive, I display a red arrow next to the number.
The neatest way I can think of doing this is to make a helper called show_with_arrow where I pass in the number. I’m trying to make the helper method pass back something like -6 ⇓ or 10 ⇑, the arrows being images.
In my show view:
<td><%= show_with_arrow keyword.compare_to(7.day.ago) %></td>
In my helper class:
def show_with_arrow(position_change)
if position_change > 0
"#{position_change} #{image_tag('bad_arrow.gif')}"
elsif position_change < 0
"#{position_change} #{image_tag('good_arrow.gif')}"
else
position_change
end
end
And it’s outputting:
-6 <img alt="Good_arrow" src="/images/good_arrow.gif?1295578152" />
instead of
-6 ⇓
I think you need to use raw() like so:
You’re on rails 3, right?