开发者

My rails helper is rendering '<' as '&lt;'! How to make it render correctly?

开发者 https://www.devze.com 2023-01-24 03:07 出处:网络
I\'m working on a simple plugin here, and this far it is working. Except my helper. Its a very simple helper, it just needs to echo a <span></span> for later javascript parsing.

I'm working on a simple plugin here, and this far it is working. Except my helper. Its a very simple helper, it just needs to echo a <span></span> for later javascript parsing.

The problem is, its not rendering the html correcty, its replacing special chars by the html equivalent code.

My plugin initializer:

ActionView::Helpers.send :include, Test

My plugin helper:

module Test    
  def only_for_testing
    render(:t开发者_运维百科ext => "<span></span>")
  end
end

When I call the only_for_testing helper inside the view, instead of rendering the "<span></span>" it renders "&lt;span&gt;&lt;/span&gt;"

I tryed remove the render, return only the string, same effect. I really dont want to create a partial for this, because its a very very simple html, and its not for layout, its just for parsing.

Any idea what i may have done wrong here?


Rails 3 escapes HTML by default in the view. You need to use the raw() helper or "HTML string here".html_safe


module Test    
  def only_for_testing
    render(:html=> "<span></span>")
  end
end


in rails 3.2, my helper did not recognize the ":html" symbol, but I believe it's been replaced with ":inline" as this is what worked for me

module IndexHelper
    def logo
        render(:inline=> "<div class='css_name'></div>")
    end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号