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(''$$(\"menu_tab\").each(function(value, index) {\nvalue.removeClassName(\"current\");\n});\n$(\"contacts_tab\").add_class_name = \"current\";\n$(\"section\").hide();\n$(\"section\").visualEffect(\"Appear\", \"{queue: \''end\''}\");''); throw e }}}); return false;">Contacts</a> 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. -- Posted via http://www.ruby-forum.com/.
Jeff Coleman
2006-Apr-18 07:37 UTC
[Rails] Re: update_page yields escaped code in callback
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 Coleman -- Posted via http://www.ruby-forum.com/.
Alan Francis
2006-Apr-18 14:30 UTC
[Rails] Re: update_page yields escaped code in callback
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 -- Posted via http://www.ruby-forum.com/.
Alan Francis
2006-Apr-18 14:34 UTC
[Rails] Re: update_page yields escaped code in callback
Alan Francis 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. > > Alane.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 %> } </script> ----------------- to use rjs to generate the javascript into a regular function, which you then pass to complete Alan and using :complete => "mycomplete" -- Posted via http://www.ruby-forum.com/.
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 %> > } > </script> > ----------------- > > to use rjs to generate the javascript into a regular function, which you > then pass to complete > > Alan > and using :complete => "mycomplete"-- Posted via http://www.ruby-forum.com/.