# Updating the page dynamically

**URL:** <https://www.ruby-forum.com/t/updating-the-page-dynamically/143875>\
**Category:** Rails\
**Created:** [July 23, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875 "2008-07-23T13:28:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 23, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/1 "2008-07-23T13:28:57Z")

</div>

Hi, I’m developing a Rails application that displays data from MySQL  
database table. I have an external python script that adds new rows to  
the table. My goal is to dynamically add new rows to the html table  
which is displayed in my browser (without reloading the page). I’ve  
read that Ajax can handle this task (“periodically\_call\_remote”). But  
I don’t want to periodically call a special method that checks if  
there is new row in the table and updates my html if needed, instead I  
want to update the page only when my python script adds a new entity.  
Any suggestions?

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 23, 2008, 1:31pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/2 "2008-07-23T13:31:53Z")

</div>

That’s not possible.  
Either the browser requests a new page or not.  
You can only force it to do so with something like  
“periodically\_call\_remote”

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 23, 2008, 1:49pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/3 "2008-07-23T13:49:29Z")

</div>

While looking for the solution, I’ve found “The Juggernaut  
plugin” (“The Juggernaut plugin for Ruby on Rails aims to  
revolutionize your Rails app by letting the server initiate a  
connection and push data to the client.”). The only bad thing is that  
the plugin can’t interact with my python script.

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 23, 2008, 3:49pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/4 "2008-07-23T15:49:48Z")

</div>

On 23 Jul 2008, at 13:40, ddtm wrote:

> While looking for the solution, I’ve found “The Juggernaut  
> plugin” (“The Juggernaut plugin for Ruby on Rails aims to  
> revolutionize your Rails app by letting the server initiate a  
> connection and push data to the client.”). The only bad thing is that  
> the plugin can’t interact with my python script.

Juggernaut is a Flash based solution for pushing data. It’s still the  
client that instantiates the connection to the push server (which runs  
seperately). Flash allows connections to be kept open in a way similar  
to Comet and other persistent connection setups. You can then interact  
with the user’s page by sending it a chunk of javascript. That  
Javascript is received by the little Flash file and injected into the  
page.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 23, 2008, 4:02pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/5 "2008-07-23T16:02:09Z")

</div>

> want to update the page only when my python script adds a new entity.  
> Any suggestions?

If the reason for this is that you don’t want to query the database  
far more frequently than the data is updated, you can use page  
caching. Add a controller method that invalidates the cache; this can  
be invoked by your python script. Then a periodic page refresh will no  
longer hit the database until it has new rows.

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 23, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/6 "2008-07-23T23:46:34Z")

</div>

Could you give me more detailed explanation (for a complete newbie)?  
Seems like the method you’ve suggested will solve my problem.

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 24, 2008, 4:16am UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/7 "2008-07-24T04:16:40Z")

</div>

Could you give a bit more detailed explanation of your solution (i’m  
new to Rails and Ajax)?

---

<div class="post-metadata">

**Author:** ![ddtm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@ddtm](https://www.ruby-forum.com/u/ddtm)\
**Post date:** [July 29, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/updating-the-page-dynamically/143875/8 "2008-07-29T20:38:53Z")

</div>

On Jul 23, 4:31 pm, ddtm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Could you give a bit more detailed explanation of your solution (i’m  
> new to Rails and Ajax)?

Caching is built-in so it is discussed in pretty much any Rails book.  
A good tutorial is here:  
[http://www.railsenvy.com/2007/2/28/rails-caching-tutorial](http://www.railsenvy.com/2007/2/28/rails-caching-tutorial)
