Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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(:text => "<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?

like image 736
Tiago Avatar asked Nov 05 '10 02:11

Tiago


1 Answers

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

like image 121
johnmcaliley Avatar answered Oct 10 '22 03:10

johnmcaliley