# DISABLE auto-escaping in image\_tag helper

**URL:** <https://www.ruby-forum.com/t/disable-auto-escaping-in-image-tag-helper/63539>\
**Category:** Rails\
**Created:** [June 16, 2006, 3:00am UTC](https://www.ruby-forum.com/t/disable-auto-escaping-in-image-tag-helper/63539 "2006-06-16T03:00:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_TSCalhoun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@Jason\_TSCalhoun](https://www.ruby-forum.com/u/Jason_TSCalhoun)\
**Post date:** [June 16, 2006, 3:00am UTC](https://www.ruby-forum.com/t/disable-auto-escaping-in-image-tag-helper/63539/1 "2006-06-16T03:00:38Z")

</div>

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:  
 ![My Company Product&copy;](https://test.ruby-forum.com/images/path/to/file.png)

The helper automatically escapes the ampersand which is part of an  
already  
escaped character. Any ideas?

---

<div class="post-metadata">

**Author:** ![Jason\_TSCalhoun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@Jason\_TSCalhoun](https://www.ruby-forum.com/u/Jason_TSCalhoun)\
**Post date:** [June 16, 2006, 6:48am UTC](https://www.ruby-forum.com/t/disable-auto-escaping-in-image-tag-helper/63539/2 "2006-06-16T06:48:45Z")

</div>

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](http://www.nabble.com/DISABLE-auto-escaping-in-image_tag-helper-t1795623.html#a4894908)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Jason\_TSCalhoun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@Jason\_TSCalhoun](https://www.ruby-forum.com/u/Jason_TSCalhoun)\
**Post date:** [June 16, 2006, 7:28am UTC](https://www.ruby-forum.com/t/disable-auto-escaping-in-image-tag-helper/63539/3 "2006-06-16T07:28:46Z")

</div>

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.
