Rails 3 - raw/html_safe not working in some cases?

Posted by Frexuz on Stack Overflow See other posts from Stack Overflow or by Frexuz
Published on 2011-10-29T11:22:06Z Indexed on 2011/11/11 17:50 UTC
Read the original article Hit count: 143

Filed under:
|

I'm having difficulties with output not being encoded even though I'm using raw or html_safe.

This one is writing out the &nbsp in my final HTLM page.

def build_tag_cloud(tag_cloud, style_list)
    tag_cloud.sort!{ |x,y| x.permalink <=> y.permalink }
    max, min = 0, 0
    tag_cloud.each do |tag|
        max = tag.followers.to_i if tag.followers.to_i > max
        min = tag.followers.to_i if tag.followers.to_i < min
    end

    divisor = ((max - min) / style_list.size) + 1

    html = ""
    tag_cloud.each do |tag|
        name = raw(tag.name.gsub('&','&amp;').gsub(' ','&nbsp;'))
        link = raw(link_to "#{name}", {:controller => "/shows", :action => "show", :permalink => tag.permalink}, :class => "#{style_list[(tag.followers.to_i - min) / divisor]}")
        html += raw("<li>#{link}</li> ")
    end
    return raw(html.to_s)
end

What is allowed in using raw and html_safe? And how should my example above be fixed?

© Stack Overflow or respective owner

Related posts about ruby-on-rails-3

Related posts about encoding