2012-03-05 36 views
0

在Rails 3.2.1帮助程序中有以下代码,即使我不需要它,我仍然会转义HTML,并且我无法弄清楚如何关闭此方法中的html转义(调用生或html_safe不工作):Rails HTML转义

module OffersHelper 
    def price_tag(amount) 
    amount = amount.to_f 
    floor = amount.floor 
    cents = ((amount - amount.floor) * 100).to_i 
    content_tag(:h2) do 
     html = floor.to_s 
     html << content_tag(:sup, cents) if cents > 0 
     html 
    end 
    end 
end 

如果我删除嵌套content_tag(SUP的标签),将HTML转义关闭...

+0

灿你详细说明你是如何调用'raw' /'html_safe'?你如何渲染字符串? – 2012-03-05 18:37:36

回答

1

尝试:

module OffersHelper 
    def price_tag(amount) 
    amount = amount.to_f 
    floor = amount.floor 
    cents = ((amount - amount.floor) * 100).to_i 
    out = content_tag(:h2) do 
     html = floor.to_s 
     html << content_tag(:sup, cents) if cents > 0 
     html 
    end 
    out.html_safe 
    end 
end