Last active
August 29, 2015 14:08
-
-
Save Sylvain303/49faa811bb33ba82b65e to your computer and use it in GitHub Desktop.
rails helper content_tag escaping html not same behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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><li>pouet: me</li>\n<li>foo: bar</li></ul>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment