Forum: Ruby on Rails Rails AJAX question, calling remote_function in a loop

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
832cf770881fdde1e604873ac425d89b?d=identicon&s=25 Gabriel Boys (gabrielboys)
on 2006-03-23 17:41
I think I may be missing something here.  I have a collection of people
I want to run through.  For each person I want to use AJAX to make a
calculation and update the page with the results.  First I tried to do
this with just links, which works fine.  It looks like this

<% @eligible_players.each do |player| %>
<tr>
<td>
<%= link_to_remote( player.player_name,
                         :update => "playerList" + player.id.to_s,
                         :url =>{ :action =>
:calc_wins_losses_for_player, :id => player.id },
                         :position => "top",
                         :complete => visual_effect(:highlight,
"playerList" + player.id.to_s, :duration => 1) ) %>
</td>
<td id=<%= "\"playerList" + player.id.to_s + "\"" %>"></td>
</tr>
<% end %>
So you have the list on the left, and when you click on a player's name
it runs the calculation and updates the page correctly.

Now my question is this, how can I do this so that the user does not
have to click on the names in order to make that call.  I was looking at
the JS reference in the rails API, and it seemed like remote_function is
the way to go.  I tried the following

<% @eligible_players.each do |player| %>
<tr>
<td>
<%= remote_function(
                         :update => "playerList" + player.id.to_s,
                         :url =>{ :action =>
:calc_wins_losses_for_player, :id => player.id },
                         :position => "top",
                         :complete => visual_effect(:highlight,
"playerList" + player.id.to_s, :duration => 1) ) %>
</td>
<td id=<%= "\"playerList" + player.id.to_s + "\"" %>"></td>
</tr>
<% end %>

but this did not work.  Just as a test I tried the
periodically_call_remote, but that obviously does not really work
correctly in this case, because it can call the same thing more than
once per person.

What am I missing here?

Thanks in advance,
Gabe
832cf770881fdde1e604873ac425d89b?d=identicon&s=25 Gabriel Boys (gabrielboys)
on 2006-03-23 18:04
Actually I guess I am missing the point that client should not be
dictating when the processing is done necessarily.  So outside of that,
is what I posted above possible?

Gabe
This topic is locked and can not be replied to.