2011-01-21 62 views
2

我在我的HTML表格中有負數和正數的列。如果數字是負數,我會在數字旁邊顯示一個綠色箭頭。如果是肯定的,我會在號碼旁邊顯示一個紅色箭頭。如何在沒有自動轉義image_tag的情況下連接輸出?

我能想到的最簡單的方法就是做一個名爲show_with_arrow的幫手,在那裏我輸入數字。我試圖讓輔助方法返回類似-6 ⇓10 ⇑,箭頭是圖像。

在我show觀點:

<td><%= show_with_arrow keyword.compare_to(7.day.ago) %></td> 

在我helper類:

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 

而且它的輸出:的

-6 <img alt="Good_arrow" src="/images/good_arrow.gif?1295578152" /> 

代替

-6 ⇓ 

回答

4

我認爲你需要使用原始()像這樣:

raw("#{position_change} #{image_tag('bad_arrow.gif')}") 

你在軌道3,對吧?

+0

哦,男孩,我試圖把image_tag之前的原始。甚至沒有想過把整個過程都寫進去。如果我將整個字符串傳遞給它,它將起作用。嘆息:) – danneu 2011-01-21 03:24:42

相關問題