'Ruby on Rails Slim Templates with HTML Entity Escaping
I have a RoR slim template with the following:
input(type="text" placeholder="I'm looking for…")
But sadly it outputs the HTML entity escape 'as-is' i.e. string literal. I'm using the rails gem 'slim' for template rendering the input field.
Desired output with the ellipsis character …
<input type="text" placeholder="I'm looking for…">
Actual output
<input type="text" placeholder="I'm looking for…">
I've tried adding a html_safe call to the end but to no avail e.g.
input(type="text" placeholder="I'm looking for…").html_safe
Thanks a bunch.
Solution 1:[1]
Self solved, simple solution, obvious answer - set of parenthesis needed:
input(type="text" placeholder=("I'm looking for…".html_safe))
Solution 2:[2]
According to Slim's website , Text is escaped by default. To prevent escape, prefix with double equals signs. So (un-intuitively),
input(type="text" placeholder=="I'm looking for…")
should work just as well.
For stand-alone unescapes, one could use
span.classname[onclick="document.getElementById('id01').style.display='none'"]
=="×"
Remember: make sure the escape character is surrounded by double quotes!
Solution 3:[3]
<%= text_field_tag nil, nil, placeholder: "I'm looking for…".html_safe %>
or give more info about your input helper
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | omgaz |
Solution 2 | Ben Leadholm |
Solution 3 | Anton Grigoryev |