Hi - I''m trying to create a widget where my rails code generates a fresh widget (which is javascript) to replace the old one. To do this, I need to insert new javascript with AJAX with RJS (so my partial begins with <script...). Is this possible? Right now, it replaces the old widget div with nothing and I get no errors. Is this a browser safeguard or something? Thanks for any help, Dino --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dino d. wrote:> I''m trying to create a widget where my rails code generates a fresh > widget (which is javascript) to replace the old one. To do this, I > need to insert new javascript with AJAX with RJS (so my partial begins > with <script...). Is this possible? Right now, it replaces the old > widget div with nothing and I get no errors. Is this a browser > safeguard or something?Wouldn''t your controller action look like this? def xhr_whatever render :update do |rjs| rjs.replace :my_div, ''<script> js blah blah blah </script>'' end end The stack should handle escaping, javascript-ing, escaping, transmitting, de-escaping, evaluating, and de-escaping that. But I''m sure there''s a better way to write your actual feature. I sling Ajax here and there all the time and never once found a need to push a ''<script>''... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. I''m writing the <script> code because i''m testing an example user of the widget, and it simply calls the website that generates the widget. so is there some escaping type issue that would prevent directly rendering a <script> tag from RJS? On Mar 30, 9:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> dino d. wrote: > > I''m trying to create a widget where my rails code generates a fresh > > widget (which is javascript) to replace the old one. To do this, I > > need to insert new javascript with AJAX with RJS (so my partial begins > > with <script...). Is this possible? Right now, it replaces the old > > widget div with nothing and I get no errors. Is this a browser > > safeguard or something? > > Wouldn''t your controller action look like this? > > def xhr_whatever > render :update do |rjs| > rjs.replace :my_div, ''<script> js blah blah blah </script>'' > end > end > > The stack should handle escaping, javascript-ing, escaping, transmitting, > de-escaping, evaluating, and de-escaping that. > > But I''m sure there''s a better way to write your actual feature. I sling Ajax > here and there all the time and never once found a need to push a ''<script>''...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 31, 4:12 am, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I''m writing the <script> code because i''m > testing an example user of the widget, and it simply calls the website > that generates the widget. so is there some escaping type issue that > would prevent directly rendering a <script> tag from RJS? >Prototype strips script tags (see http://prototypejs.org/api/element/replace ) Fred> On Mar 30, 9:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > dino d. wrote: > > > I''m trying to create a widget where my rails code generates a fresh > > > widget (which is javascript) to replace the old one. To do this, I > > > need to insert new javascript with AJAX with RJS (so my partial begins > > > with <script...). Is this possible? Right now, it replaces the old > > > widget div with nothing and I get no errors. Is this a browser > > > safeguard or something? > > > Wouldn''t your controller action look like this? > > > def xhr_whatever > > render :update do |rjs| > > rjs.replace :my_div, ''<script> js blah blah blah </script>'' > > end > > end > > > The stack should handle escaping, javascript-ing, escaping, transmitting, > > de-escaping, evaluating, and de-escaping that. > > > But I''m sure there''s a better way to write your actual feature. I sling Ajax > > here and there all the time and never once found a need to push a ''<script>''...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred. I see in the code that you''re correct (however that link implies that you can do this, it shows an example of how to add a script tag). So generically, is it ever possible to use an ajax call, such as link_to_remote, where response partial renders javascript? Thanks, Dino On Mar 31, 4:54 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 31, 4:12 am, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I''m writing the <script> code because i''m > > testing an example user of the widget, and it simply calls the website > > that generates the widget. so is there some escaping type issue that > > would prevent directly rendering a <script> tag from RJS? > > Prototype strips script tags (seehttp://prototypejs.org/api/element/replace > ) > > Fred > > > On Mar 30, 9:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > dino d. wrote: > > > > I''m trying to create a widget where my rails code generates a fresh > > > > widget (which is javascript) to replace the old one. To do this, I > > > > need to insert new javascript with AJAX with RJS (so my partial begins > > > > with <script...). Is this possible? Right now, it replaces the old > > > > widget div with nothing and I get no errors. Is this a browser > > > > safeguard or something? > > > > Wouldn''t your controller action look like this? > > > > def xhr_whatever > > > render :update do |rjs| > > > rjs.replace :my_div, ''<script> js blah blah blah </script>'' > > > end > > > end > > > > The stack should handle escaping, javascript-ing, escaping, transmitting, > > > de-escaping, evaluating, and de-escaping that. > > > > But I''m sure there''s a better way to write your actual feature. I sling Ajax > > > here and there all the time and never once found a need to push a ''<script>''...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 31, 4:03 pm, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks Fred. I see in the code that you''re correct (however that link > implies that you can do this, it shows an example of how to add a > script tag). So generically, is it ever possible to use an ajax call, > such as link_to_remote, where response partial renders javascript? >I suppose you could just assign stuff to element.innerHTML without using prototype. ALso prototype does actually eval the script tags, it just doesn''t leave them hanging around in the DOM. Fred> Thanks, > Dino > > On Mar 31, 4:54 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 31, 4:12 am, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I''m writing the <script> code because i''m > > > testing an example user of the widget, and it simply calls the website > > > that generates the widget. so is there some escaping type issue that > > > would prevent directly rendering a <script> tag from RJS? > > > Prototype strips script tags (seehttp://prototypejs.org/api/element/replace > > ) > > > Fred > > > > On Mar 30, 9:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > dino d. wrote: > > > > > I''m trying to create a widget where my rails code generates a fresh > > > > > widget (which is javascript) to replace the old one. To do this, I > > > > > need to insert new javascript with AJAX with RJS (so my partial begins > > > > > with <script...). Is this possible? Right now, it replaces the old > > > > > widget div with nothing and I get no errors. Is this a browser > > > > > safeguard or something? > > > > > Wouldn''t your controller action look like this? > > > > > def xhr_whatever > > > > render :update do |rjs| > > > > rjs.replace :my_div, ''<script> js blah blah blah </script>'' > > > > end > > > > end > > > > > The stack should handle escaping, javascript-ing, escaping, transmitting, > > > > de-escaping, evaluating, and de-escaping that. > > > > > But I''m sure there''s a better way to write your actual feature. I sling Ajax > > > > here and there all the time and never once found a need to push a ''<script>''...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry for the dumb follow up, but can you do that in RJS (update an elements innerHTML directly) ? Thanks Fred, Dino On Mar 31, 11:15 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 31, 4:03 pm, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks Fred. I see in the code that you''re correct (however that link > > implies that you can do this, it shows an example of how to add a > > script tag). So generically, is it ever possible to use an ajax call, > > such as link_to_remote, where response partial renders javascript? > > I suppose you could just assign stuff to element.innerHTML without > using prototype. ALso prototype does actually eval the script tags, it > just doesn''t leave them hanging around in the DOM. > > Fred > > > Thanks, > > Dino > > > On Mar 31, 4:54 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Mar 31, 4:12 am, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I''m writing the <script> code because i''m > > > > testing an example user of the widget, and it simply calls the website > > > > that generates the widget. so is there some escaping type issue that > > > > would prevent directly rendering a <script> tag from RJS? > > > > Prototype strips script tags (seehttp://prototypejs.org/api/element/replace > > > ) > > > > Fred > > > > > On Mar 30, 9:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > dino d. wrote: > > > > > > I''m trying to create a widget where my rails code generates a fresh > > > > > > widget (which is javascript) to replace the old one. To do this, I > > > > > > need to insert new javascript with AJAX with RJS (so my partial begins > > > > > > with <script...). Is this possible? Right now, it replaces the old > > > > > > widget div with nothing and I get no errors. Is this a browser > > > > > > safeguard or something? > > > > > > Wouldn''t your controller action look like this? > > > > > > def xhr_whatever > > > > > render :update do |rjs| > > > > > rjs.replace :my_div, ''<script> js blah blah blah </script>'' > > > > > end > > > > > end > > > > > > The stack should handle escaping, javascript-ing, escaping, transmitting, > > > > > de-escaping, evaluating, and de-escaping that. > > > > > > But I''m sure there''s a better way to write your actual feature. I sling Ajax > > > > > here and there all the time and never once found a need to push a ''<script>''...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 31, 9:53 pm, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Sorry for the dumb follow up, but can you do that in RJS (update an > elements innerHTML directly) ? >Well there''s the assigns thing in RJS, failing that you can execute arbitrary javascript with << Fred> Thanks Fred, > Dino > > On Mar 31, 11:15 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 31, 4:03 pm, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks Fred. I see in the code that you''re correct (however that link > > > implies that you can do this, it shows an example of how to add a > > > script tag). So generically, is it ever possible to use an ajax call, > > > such as link_to_remote, where response partial renders javascript? > > > I suppose you could just assign stuff to element.innerHTML without > > using prototype. ALso prototype does actually eval the script tags, it > > just doesn''t leave them hanging around in the DOM. > > > Fred > > > > Thanks, > > > Dino > > > > On Mar 31, 4:54 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On Mar 31, 4:12 am, dinoD <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I''m writing the <script> code because i''m > > > > > testing an example user of the widget, and it simply calls the website > > > > > that generates the widget. so is there some escaping type issue that > > > > > would prevent directly rendering a <script> tag from RJS? > > > > > Prototype strips script tags (seehttp://prototypejs.org/api/element/replace > > > > ) > > > > > Fred > > > > > > On Mar 30, 9:39 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > dino d. wrote: > > > > > > > I''m trying to create a widget where my rails code generates a fresh > > > > > > > widget (which is javascript) to replace the old one. To do this, I > > > > > > > need to insert new javascript with AJAX with RJS (so my partial begins > > > > > > > with <script...). Is this possible? Right now, it replaces the old > > > > > > > widget div with nothing and I get no errors. Is this a browser > > > > > > > safeguard or something? > > > > > > > Wouldn''t your controller action look like this? > > > > > > > def xhr_whatever > > > > > > render :update do |rjs| > > > > > > rjs.replace :my_div, ''<script> js blah blah blah </script>'' > > > > > > end > > > > > > end > > > > > > > The stack should handle escaping, javascript-ing, escaping, transmitting, > > > > > > de-escaping, evaluating, and de-escaping that. > > > > > > > But I''m sure there''s a better way to write your actual feature. I sling Ajax > > > > > > here and there all the time and never once found a need to push a ''<script>''...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---