Updating the page dynamically

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?

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"

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

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.

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

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