[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Looping though renders in Rails

Tony Targonski

4/11/2005 9:39:00 PM

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



2 Answers

acharlieblue

4/12/2005 2:05:00 AM

0

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.

Douglas Livingstone

4/12/2005 9:37:00 AM

0

On Apr 11, 2005 10:38 PM, Tony Targonski <Tony.Targonski@quest.com> wrote:
> In theory this should go through

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