# AJAX question: delayed update of messages

**URL:** <https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603>\
**Category:** Rails\
**Created:** [May 4, 2008, 10:26am UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603 "2008-05-04T10:26:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 4, 2008, 10:26am UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/1 "2008-05-04T10:26:41Z")

</div>

Hello,

I’d like to start a process on the server and update the client with  
information about the process, such as

‘starting application …’ (wait 20 seconds) ‘done’

and so on. Which strategy should I use? I have tried to use multiple  
render :update do |page| … end, but this is not allowed (OK,  
obviously). And somthing like:

page.insert\_html :bottom, ‘textarea’, ‘before sleep’  
sleep(20)  
page.insert\_html :bottom, ‘textarea’, ‘after sleep’

did not work because both messages are sent back at the same time(?). So  
what could I do to update the browser’s text? I know of  
periodically\_call\_remote, but that way I’d have to remember the state on  
the server side, right?

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 4, 2008, 12:14pm UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/2 "2008-05-04T12:14:08Z")

</div>

Patrick G. wrote:

> Hello,
> 
> I’d like to start a process on the server and update the client with  
> information about the process, such as
> 
> ‘starting application …’ (wait 20 seconds) ‘done’
> 
> and so on. Which strategy should I use? I have tried to use multiple  
> render :update do |page| … end, but this is not allowed (OK,  
> obviously). And somthing like:
> 
> page.insert\_html :bottom, ‘textarea’, ‘before sleep’  
> sleep(20)  
> page.insert\_html :bottom, ‘textarea’, ‘after sleep’
> 
> did not work because both messages are sent back at the same time(?). So  
> what could I do to update the browser’s text? I know of  
> periodically\_call\_remote, but that way I’d have to remember the state on  
> the server side, right?
> 
> Patrick

The periodicalUpdater from the prototype js library might be what you  
want.  
See [Prototype API Documentation | Ajax.PeriodicalUpdater (Deprecated URL)](http://www.prototypejs.org/api/ajax/periodicalUpdater) and  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000959](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000959)

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 4, 2008, 6:08pm UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/3 "2008-05-04T18:08:37Z")

</div>

Hello,

> The periodicalUpdater from the prototype js library might be what you  
> want.  
> See [Prototype API Documentation | Ajax.PeriodicalUpdater (Deprecated URL)](http://www.prototypejs.org/api/ajax/periodicalUpdater) and  
> [http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000959](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000959)

But then I’d have to remember the state of that client on the server,  
right? I mean: all the output generated between two periodical Updater  
requests has to be saved and then sent to the client. This is something  
I’d like to avoid if it is possible.

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 5, 2008, 6:52am UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/4 "2008-05-05T06:52:08Z")

</div>

backgroundrb? not sure

On Sun, May 4, 2008 at 10:08 AM, Patrick G.

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 5, 2008, 8:22pm UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/5 "2008-05-05T20:22:58Z")

</div>

Patrick G. wrote:

> Roger P. wrote:
> 
> > backgroundrb? not sure
> 
> That’s a cool thing! Not really solving the problem I have here, but it  
> will solve other problems!
> 
> Thanks,
> 
> Patrick

I googled with the keyword “AJAX push” and it came with a few  
interesting results  
What about this:  
[http://home.flowdev.de/wordpress/index.php](http://home.flowdev.de/wordpress/index.php) (Look for RTRails)  
[http://www.lightstreamer.com/](http://www.lightstreamer.com/)  
[http://www.pushlets.com/](http://www.pushlets.com/)

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 5, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/6 "2008-05-05T20:04:27Z")

</div>

Roger P. wrote:

> backgroundrb? not sure

That’s a cool thing! Not really solving the problem I have here, but it  
will solve other problems!

Thanks,

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 5, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/7 "2008-05-05T21:10:54Z")

</div>

Danny H. wrote:

> Patrick G. wrote:
> 
> > Roger P. wrote:
> > 
> > > backgroundrb? not sure
> > 
> > That’s a cool thing! Not really solving the problem I have here, but it  
> > will solve other problems!
> > 
> > Thanks,
> > 
> > Patrick
> 
> I googled with the keyword “AJAX push” and it came with a few  
> interesting results  
> What about this:  
> [http://home.flowdev.de/wordpress/index.php](http://home.flowdev.de/wordpress/index.php) (Look for RTRails)  
> [http://www.lightstreamer.com/](http://www.lightstreamer.com/)  
> [http://www.pushlets.com/](http://www.pushlets.com/)

Hello Danny,

thanks for the keywords, somehow these didn’t come into my mind. I have  
not implemented anything yet, but this will guide me in the right  
direction. Thans again!

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [May 5, 2008, 10:01pm UTC](https://www.ruby-forum.com/t/ajax-question-delayed-update-of-messages/136603/8 "2008-05-05T22:01:11Z")

</div>

You might want to check out the juggernaut gem and associated plugin.  
In short, it sticks a little flash app into your page which ultimately  
allows you to _push_ from the webserver to the client browser. There  
are various options for identifying clients and channels so the  
messages you push can be as broad or restricted as you like.  
Typically you end up pushing javascript to the client to update the  
state of the page.

On May 5, 3:10 pm, Patrick G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
