Gabriel Boys
2006-Mar-23 16:41 UTC
[Rails] Rails AJAX question, calling remote_function in a loop
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 -- Posted via http://www.ruby-forum.com/.
Gabriel Boys
2006-Mar-23 17:04 UTC
[Rails] Re: Rails AJAX question, calling remote_function in a loop
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 -- Posted via http://www.ruby-forum.com/.