Skip to content

Instantly share code, notes, and snippets.

@Sylvain303
Last active August 29, 2015 14:08
Show Gist options
  • Save Sylvain303/49faa811bb33ba82b65e to your computer and use it in GitHub Desktop.
Save Sylvain303/49faa811bb33ba82b65e to your computer and use it in GitHub Desktop.
rails helper content_tag escaping html not same behavior
# from rails console
# foo is defined https://gist.github.com/Sylvain303/5899c453579871bfbfc4
# here redmine issue helper
foo = ActionView::Base.new
foo.extend IssuesHelper
foo.extend CustomFieldsHelper
items = [ "pouet: me", "foo: bar" ]
items.map{|s| foo.content_tag('li', s)}
# => ["<li>pouet: me</li>", "<li>foo: bar</li>"]
foo.content_tag('ul', items.map{|s| foo.content_tag('li', s)}.join("\n").html_safe)
# => "<ul><li>pouet: me</li>\n<li>foo: bar</li></ul>"
# but escaped html here…
output = items.map{|s| foo.content_tag('li', s)}.join("\n")
# => "<li>pouet: me</li>\n<li>foo: bar</li>"
foo.content_tag('ul', output)
# => "<ul>&lt;li&gt;pouet: me&lt;/li&gt;\n&lt;li&gt;foo: bar&lt;/li&gt;</ul>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment