Is there any way to disable image_tag’s automatic escaping of special
html
entities in it’s :alt tag?
Example:
From the controller:
@sale[‘title’] = ‘My Company Product©’
In the view:
<%= image_tag(‘path/to/file.png’, :alt => @sale[‘title’]) %>
Output:
The helper automatically escapes the ampersand which is part of an
already
escaped character. Any ideas?
This happens way down in tag_helper.rb.
def tag(name, options = nil, open = false)
"<#{name}#{tag_options(options.stringify_keys) if options}" +
(open
? “>” : " />")
end
The call to tag_options (a private method) is causing your pain. It’s
kind
of a big hammer, but you could write a little plugin that overrides this
behavior. But remember, the behavior is there for a reason: To keep
meddlesome little hackers from injecting unsave data into your pages.
View this message in context:
http://www.nabble.com/DISABLE-auto-escaping-in-image_tag-helper-t1795623.html#a4894908
Sent from the RubyOnRails Users forum at Nabble.com.
How about not escaping the data in the DB?
After all, the escaping is for HTML. It certainly
shouldn’t be escaped in the DB!
Of course, I’m quite clear that this doesn’t
solve your problem for your current data, but
I’d certainly take a moment to figure out how
to prevent this from happening in the future.
–
– Tom M.