6

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?

Tiago
  • 2,966
  • 4
  • 33
  • 41

3 Answers3

16

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

johnmcaliley
  • 11,015
  • 2
  • 42
  • 47
6
module Test    
  def only_for_testing
    render(:html=> "<span></span>")
  end
end
thenengah
  • 42,557
  • 33
  • 113
  • 157
3

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
sqlexception
  • 194
  • 2
  • 3