streaming response body to client?

So I'd like to stream my response body to the client.

At least under Rails2, it looks like you can pass a Proc to render :text, to do that.

I am in a Rails2 app right now, but will upgrade to Rails3 sometime in the next couple months, so don't want to set myself up for failure. Anyone know the status of streaming responses in Rails3? Is it possible? Is there a different API to do so? (Seems like using Rack api, it definitely must be possible, since Rails3 is all rack, and rack is fine with iteratively-delivered responses, but it's not entirely clear to me how to do it).

On top of that, even in Rails2, I'm having an awful lot of trouble setting custom headers in the response using the render :text => proc pattern. The proc, according to what limited docs I've found, takes two args, the first one is a 'response', which I should be able to set headers on, but I can't seem to make them stick.

Can anyone give me the lowdown on streaming responses in Rails? Maybe a good example, even one that sets headers too?

I would love to hear more on this as well. Currently suffering in Rails3 due to this not having a clear solution.

Same here.

If you look around in the group, you'll find opinions like:

"In rails 3, the render :text => lambda { ... } is definitely broken. "

So far I'm on the same page with this issue (:

Martin

I managed to find a workaround for streaming which worked:

Here's the lighthouse ticket for this issue: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4554-render-text-proc-regression#ticket-4554-15

And an excellent post about this issue: http://patshaughnessy.net/2010/10/11/activerecord-with-large-result-sets-part-2-streaming-data/

To summarize: 1) render :text => proc seems to be broken in Rails3 2) the documentation is not updated to reflect it's broken (or deprecated)

3) you can use the self.response_body = proc approach like this: