# Update\_page yields escaped code in callback

**URL:** <https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077>\
**Category:** Rails\
**Created:** [April 18, 2006, 8:28am UTC](https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077 "2006-04-18T08:28:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evronm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@evronm](https://www.ruby-forum.com/u/evronm)\
**Post date:** [April 18, 2006, 8:28am UTC](https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077/1 "2006-04-18T08:28:40Z")

</div>

Hi All,

The subject pretty well describes what I am experiencing. This line in  
an .rhtml template:

\<%= link\_to\_remote menu\_item.humanize,  
{:update =\> ‘section’,  
:url =\>{:controller =\> menu\_item},  
:complete =\> update\_page do |page|  
page.activate\_tab("#{menu\_item}_tab", 'menu_’)  
page[‘section’].hide  
page[‘section’].visual\_effect(‘Appear’, ‘{queue: ‘end’}’)  
end  
},  
:id =\> “#{menu\_item}\_tab”, :class =\> ‘menu\_tab’ %\>

yields this godawful mess (the ‘activate\_tab’ method is in the  
ApplicationHelper, but all the javascript is being escaped regardless of  
where it’s generated):

# \<a class=“menu\_tab” href="#" id=“contacts\_tab” onclick="new Ajax.Updater(‘section’, ‘/contacts’, {asynchronous:true, evalScripts:true, onComplete:function(request){try { $$(“menu\_tab”).each(function(value, index) { value.removeClassName(“current”); }); $(“contacts\_tab”).add\_class\_name = “current”; $(“section”).hide(); $(“section”).visualEffect(“Appear”, “{queue: ‘end’}”); } catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(’$$(&quot;menu\_tab&quot;).each(function(value, index) {\nvalue.removeClassName(&quot;current&quot;);\n});\n$(&quot;contacts\_tab&quot;).add\_class\_name

&quot;current&quot;;\n$(&quot;section&quot;).hide();\n$(&quot;section&quot;).visualEffect(&quot;Appear&quot;,  
&quot;{queue: ‘end’}&quot;);’); throw e }}}); return  
false;"\>Contacts

I looked through the docs and even scanned the code a bit, but I can’t  
figure out where escape\_javascript is being called or how to prevent it  
from being called.

Any help would be greatly appreciated.

Thanks much,

-Mike.

---

<div class="post-metadata">

**Author:** ![evronm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@evronm](https://www.ruby-forum.com/u/evronm)\
**Post date:** [April 18, 2006, 9:37am UTC](https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077/2 "2006-04-18T09:37:10Z")

</div>

Mike Evron wrote:

> 

> I looked through the docs and even scanned the code a bit, but I can’t  
> figure out where escape\_javascript is being called or how to prevent it  
> from being called.
> 
> Any help would be greatly appreciated.
> 
> Thanks much,
> 
> -Mike.

Try removing the :update parameter from your link\_to\_remote call, see if  
that has any effect.

Jeff C.man

---

<div class="post-metadata">

**Author:** ![evronm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@evronm](https://www.ruby-forum.com/u/evronm)\
**Post date:** [April 18, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077/3 "2006-04-18T16:34:19Z")

</div>

Alan F. wrote:

> Mike Evron wrote:
> 
> > Hi All,
> > 
> > The subject pretty well describes what I am experiencing. This line in  
> > an .rhtml template:
> > 
> > \<%= link\_to\_remote menu\_item.humanize,  
> > {:update =\> ‘section’,  
> > :url =\>{:controller =\> menu\_item},  
> > :complete =\> update\_page do |page|  
> > page.activate\_tab("#{menu\_item}_tab", 'menu_’)  
> > page[‘section’].hide  
> > page[‘section’].visual\_effect(‘Appear’, ‘{queue: ‘end’}’)  
> > end  
> > },  
> > :id =\> “#{menu\_item}\_tab”, :class =\> ‘menu\_tab’ %\>
> 
> I think the :complete takes a javascript function _name_, rather than  
> the whole function.
> 
> Alan

e.g. :complete =\> “undoRequestCompleted(request)” or something.

You might try:

* * *

## \<script type = “text/javascript\> function mycomplete() { \<%= update\_page do |page| page.activate\_tab(”#{menu\_item}_tab", 'menu_’) page[‘section’].hide page[‘section’].visual\_effect(‘Appear’, ‘{queue: ‘end’}’) end %\> }

to use rjs to generate the javascript into a regular function, which you  
then pass to complete

Alan  
and using :complete =\> “mycomplete”

---

<div class="post-metadata">

**Author:** ![evronm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@evronm](https://www.ruby-forum.com/u/evronm)\
**Post date:** [April 18, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077/4 "2006-04-18T16:30:34Z")

</div>

Mike Evron wrote:

> Hi All,
> 
> The subject pretty well describes what I am experiencing. This line in  
> an .rhtml template:
> 
> \<%= link\_to\_remote menu\_item.humanize,  
> {:update =\> ‘section’,  
> :url =\>{:controller =\> menu\_item},  
> :complete =\> update\_page do |page|  
> page.activate\_tab("#{menu\_item}_tab", 'menu_’)  
> page[‘section’].hide  
> page[‘section’].visual\_effect(‘Appear’, ‘{queue: ‘end’}’)  
> end  
> },  
> :id =\> “#{menu\_item}\_tab”, :class =\> ‘menu\_tab’ %\>

I think the :complete takes a javascript function _name_, rather than  
the whole function.

Alan

---

<div class="post-metadata">

**Author:** ![evronm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f1d935/32.png) [@evronm](https://www.ruby-forum.com/u/evronm)\
**Post date:** [April 18, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/update-page-yields-escaped-code-in-callback/58077/5 "2006-04-18T18:49:05Z")

</div>

Wow! You guys are right. It’s been escaping my manual javascript the  
whole time and I didn’t even notice it, because it worked! And who would  
have though such badly mangled code would work… The only thing busted  
is effects queues

Guess I have to restructure a couple of things in my app unless somebody  
can figure out how to make it stop doing that. There really should be a  
way…

Thanks for all the help.

> > I think the :complete takes a javascript function _name_, rather than  
> > the whole function.
> > 
> > Alan
> 
> e.g. :complete =\> “undoRequestCompleted(request)” or something.
> 
> You might try:
> 
> * * *
> 
> ## \<script type = “text/javascript\> function mycomplete() { \<%= update\_page do |page| page.activate\_tab(”#{menu\_item}_tab", 'menu_’) page[‘section’].hide page[‘section’].visual\_effect(‘Appear’, ‘{queue: ‘end’}’) end %\> }
> 
> to use rjs to generate the javascript into a regular function, which you  
> then pass to complete
> 
> Alan  
> and using :complete =\> “mycomplete”
