views:

81

answers:

3

How can i autoreload every few seconds a partial, just like in twitter seach. i am using rails and hobo.

+1  A: 

As far as I can see, there is no common approach to do this kind of stuff. As I imagine, you would need to asynchronously query the server for updates every once in a while, but it can become quite cumbersome for the server if there are many clients polling for new data all the time.

I would suggest using something like APE to maintain a constant connection to the server and get fresh data as soon as it is available.

Igor Zinov'yev
A: 

It may be time to roll up your sleeves and view source. I've heard of folks using Juggernaut to keep a live server connection open for such real-time things.

Barry Hess
+4  A: 

The simplest thing to use in Rails is periodically_call_remote . Example from Agile Web Development with Rails, Third Edition follows:

<div id="inbox_status">Unknown</div>
<%= periodically_call_remote :url => {:action => 'get_inbox_status',
:user_id => @user.id},
:update => 'inbox_status',
:frequency => 60,
:condition => "$('inbox_status').innerHTML == 'Unknown'" ,
:before => "Element.show('progress_indicator')" ,
:complete => "Element.hide('progress_indicator')" %>
MattMcKnight
With a little work you can cut down on the processing time, by passing the time the page was rendered at and only fetching/returning only the new updates since the last poll.
EmFi