Hi All! I''m kind of new o ruby so please apologize my stupid questions on advanced... I''m using render :update do |page| page.replaca_html :element , :partial => ''apartial'' end This is working well, since I see in the page the following code: try { Element.update("element", ""); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''Element.update("element", \"");''); throw e } I simplified the output. My problem is that no script tag is generated and the code is not executed! How can I fix this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pedro Cardoso wrote:> I''m using > render :update do |page| > page.replaca_html :element , :partial => ''apartial'' > endIs this inside a view, or up in a controller?> This is working well, since I see in the page the following code: > > try > { > Element.update("element", ""); > } catch (e) > { > alert(''RJS error:\n\n'' + e.toString()); > alert(''Element.update("element", \"");''); > throw e > } > > I simplified the output. > > My problem is that no script tag is generated and the code is not > executed! > > How can I fix this?Inside a view, use update_page_tag(). I think render :update works different inside a view. You could, for example, stack up many render :updates inside one view <script> tag. But prefer using a controller, because "that''s what everyone else does". If possible! -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!!n --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5 December 2006 15:43, Pedro Cardoso wrote:> I''m using > render :update do |page| > page.replaca_html :element , :partial => ''apartial'' > end > > My problem is that no script tag is generated and the code is not > executed!What did you expect ? You''ve asked controller to update HTML, so controller generated javascript to do that. You can then execute it on page. But if you used e.g. remote_function with :update parameter, then Ajax.Request expect some HTML from server to put into element you''ve specified. I think it is (almost always) better to use remote_function without :update argument, because it gives you more flexibility (not just updating contents of single element). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
render :update is meant be used in the controller as a response to an AJAX request, it returns pure javascript that will be executed by tha AJAX code that called the action ... so of course there are no <script> tags. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I used it in the controller. And it did what I was expecting! Anyway, I''m using this do display the errors in a specific part of my html, so this is no response to a request. The following quote is from the manual "Use this in your Ajax response bodies, either in a <script> tag or as plain JavaScript sent with a Content-type of "text/javascript"". So, this is my question, how do I do that? How can I add the script tags? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pedro Cardoso wrote:> Anyway, I''m using this do display the errors in a specific part of my > html, so this is no response to a request.Everything''s a responds to a request. Someone asked if you were doing a response to an Ajax request. You are apparently injecting JavaScript when the page first paints.> The following quote is from the manual "Use this in your Ajax response > bodies, either in a <script> tag or as plain JavaScript sent with a > Content-type of "text/javascript"". > > So, this is my question, how do I do that? How can I add the script > tags?You ensure that the strings with <script> appear around it. If it''s in your controller, and if you are not rendering an Ajax-style request, then use ''<script>'' + and + ''</script>'' around the string it returns. If you are inside a view, go <script><%= render :etc %></script> Note that there are few reasons to do the former. Yet there might be many reasons to do the latter - sharing the first-paint code with the update code, for example. And note a purist would need the type=''text/javascript'', the // CDATA escape things. I don''t know what function returns those. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---