Partial update

I have a partial on main page that displays current scores of game. The
latest scores keep coming in database. I want to update that partial
after every 5 seconds with values from db so that latest scores will be
displayed. How can I do that?

you can handle that from you view:

<%= periodically_call_remote(:url => mycontroller_path(), :method =>
:get, :frequency => 5) %>

your controller must return the update as ajax in that case
if you have some tag with id ‘score_list’ it would look like

@new_scores = ScoreList.find(…)
render :update do |page|
page.replace_html “score_list”, :partial => “my_partial”, :collection
=> @new_scores
end

On 15 Nov 2007, at 11:27, Vapor … wrote:

I have a partial on main page that displays current scores of game.
The
latest scores keep coming in database. I want to update that partial
after every 5 seconds with values from db so that latest scores will
be
displayed. How can I do that?

You probably want to have a look at periodically_call_remote

Fred

Thorsten M. wrote:

you can handle that from you view:

<%= periodically_call_remote(:url => mycontroller_path(), :method =>
:get, :frequency => 5) %>

your controller must return the update as ajax in that case
if you have some tag with id ‘score_list’ it would look like

@new_scores = ScoreList.find(…)
render :update do |page|
page.replace_html “score_list”, :partial => “my_partial”, :collection
=> @new_scores
end

Perfect!!! Many thanks :slight_smile: