Sir Railists: Oggle this pseudo-Rails: <div id=''self'' > <%= periodically_call_remote(:update => ''self'', :action => ''yo'' ... ) %> </div> def yo if new_data update :text => format(new_data) else update :text => periodically_call_remote(:update => ''self'', :action => ''yo'' ... ) end end The intent is to update a div until new data appears, then display it once and stop updating the div. I haven''t typed this in yet because I suspect it won''t work. I suspect that the browser will evaluate the JavaScript representation of periodically_call_remote(), then spawn a window timer. The timer will send AJAX, and the reply will contain another JavaScript representation of periodically_call_remote(). The new JavaScript will not turn off the original timer. Then the browser will evaluate it and spawn a window timer. The effect will keep rolling along until the browser slows down with lots of simultaneous AJAX calls... How to fix this? How to keep updating until data arrive, then stop? -- Phlip http://www.greencheese.us/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 -~----------~----~----~----~------~----~------~--~---
cremes.devlist-ee4meeAH724@public.gmane.org
2006-Nov-29 20:05 UTC
Re: periodically_call_remote updates self to turn self off??
On Wednesday, November 29, 2006, at 01:19PM, "Phlip" <phlip2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >Sir Railists: > >Oggle this pseudo-Rails: > > <div id=''self'' > > <%= periodically_call_remote(:update => ''self'', > :action => ''yo'' >... ) %> > </div> > >def yo > if new_data > update :text => format(new_data) > else > update :text => periodically_call_remote(:update => ''self'', > > :action => ''yo'' ... ) > end >end > >The intent is to update a div until new data appears, then display it once >and stop updating the div. > >I haven''t typed this in yet because I suspect it won''t work.Your suspicions are correct. Do something like this (don''t call a div ''self''... it might conflict with the Ruby Ojbect #self): <script>stop_polling = false;</script> <div id=''myself'' > <%= periodically_call_remote(:url => {:action => ''updater''}, :frequency => 5, :condition => "stop_polling == false") %> After you update the information in div ''myself'' once, set ''stop_polling = true''. cr --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
cremes.devlist wrote:>>The intent is to update a div until new data appears, then display it once >>and stop updating the div.>>I haven''t typed this in yet because I suspect it won''t work.> Your suspicions are correct. Do something like this > (don''t call a div ''self''... it might conflict with the Ruby Ojbect #self):I trust my syntax hiliting. (:-)> <script>stop_polling = false;</script>Thanks - that''s just what I researched, based on this: http://rubyforge.org/pipermail/backgroundrb-devel/2006-August/000248.html I did what you said, much better than that post, with only two improvements:> <div id=''myself'' >I didn''t put the periodically_call_remote() inside its own updated div! (I also don''t e-mail a new one back to myself!)> <%= periodically_call_remote(:url => {:action => ''updater''}, > :frequency => 5, > :condition => "stop_polling == false") %>And I followed the advice "state things positively". So the variable is ''keep_polling'', and the condition is one tick simpler: :condition=>''keep_polling''. Now for my next magical trick, I shall add a number to stop_polling, to make it stop_polling_2, to put many of these naughty things all over my page! (Going forward, I will replace every periodically_call_remote() with a single one that intelligently updates with replace_html, only those divs that have changed. But that is another story!) -- Phlip http://www.greencheese.us/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 -~----------~----~----~----~------~----~------~--~---