Using: Rails 3.2.11 & Ruby 1.8.7
I am having some serious problem trying to make label_tag
output html. Basically it boils down to:
<%= label_tag "This will <strong>not</strong> work!" %>
I have tried:
<%= raw label_tag "This will <strong>not</strong> work!" %>
<%= label_tag raw "This will <strong>not</strong> work!" %>
<%= label_tag "This will <strong>not</strong> work!".html_safe %>
<%= (label_tag "This will <strong>not</strong> work!").html_safe %>
I have installed the gem 'rails_xss'.
Nothing works!
Even though I can find a lot of related problems with escaping html where people having problems with raw and html_safe not working, nothing is related to label_tag. I cannot use f.label for this issue.
This used to work on the same application but after a few updates (where Rails 3.0.3 -> 3.2.11 was the major one) it stopped working. I didn't notice when this happened so I am not sure what caused the problem.
Can you replicate? Do you have a solution?
The problem is that the first argument to label_tag
is supposed to be the label name. If you wish to display custom content inside the tag, that must be the second argument.
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-label_tag
Try this:
<%= label_tag "my label name", raw("This will <strong>not</strong> work!") %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With