Looping though renders in Rails

I am trying to get Rails to loop though a number of functions within a
controller, rendering the status in the process. A simplified version
would be something like

class TestController < ApplicationController
  def index
    redirect_to :action => 'foo', :id => 2
  end
  
  def foo
    if @params["id"].to_i > 0 then
    redirect_to :action => 'foo', :id => @params["id"].to_i
- 1
    end
  end
end

Where the template for 'foo' is something as simple as

<%= @params["id"] %>
<% sleep 1 %>

In theory this should go through
foo/2
foo/1
foo/0
displaying each, but that is not the case. Although sleep function is
executed during each unique ID, no renders take place until the loop has
gone down to 0.

Can anyone think of a workaround for this problem? I have a loop to be
executed and want to let the user know how far in the program is. Also
(more importantly) prevent FastCGI from timing out during this
indefinitely long procedure.

Thank you,
--Tony

The code of an action is executed before it's rendered, so your
redirect is cutting off the action before anything is sent to the user.
You might be able to get away with it by calling render_action before
redirecting. Though I'm not sure what you mean to accomplish, but it
seems like there must be a better way than continuous forced reloading.

The redirects send a 302 redirect to the browser, so it doesn't send
any acctual content to the user until it gets to the last one, where
it sends a 200 responce with content.

hth,
Douglas

···

On Apr 11, 2005 10:38 PM, Tony Targonski <Tony.Targonski@quest.com> wrote:

In theory this should go through