Update_page yields escaped code in callback

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.

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

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”

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

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”