This project is archived and is in readonly mode.
render :text => proc { ... } regression
-
Trotter Cashion
We (Sean Grieve and myself) think we fixed this in the way you want. We made the patch on the 3-0-stable branch. If that's incorrect, let us know and we'll make it work on master.
-
Lake
Your patch applies cleanly to master and the tests are passing.
+1
-
jrochkind
I definitely need streaming response behavior in Rails3. If this is the patch neccessary to get it again, would be awesome if someone committed it.
-
Ryan Bigg
Automatic cleanup of spam.
-
Rodrigo Rosenfeld Rosas
Sorry, I need to be more specific. We need to remove the mention "Tip: if you want to stream large amounts of on-the-fly generated data to the browser, then use render :text => proc { ... } instead. See ActionController::Base#render for more information."
http://api.rubyonrails.org/classes/ActionController/Streaming.html
And we need some alternative to data streaming. Unfortunately, just using "self.response_body = proc {|response, output| 5.times{output.write 'Testing
'; sleep 1} }" won't flush, until the end, for instance.So, the deprecation warning for the proposed patch is not correct enough yet...
-
Kevin Menard
Rodrigo's point is very good. I'd go so far as to say the deprecation message is just flat out wrong. It's not deprecated if the expected behavior is already removed. And currently there isn't a real way to stream large amounts of generated data.
-
blaxter
Rodrigo, adding
output.flushoroutput.write "Testing\n"you should get the response in the client without any wait. -
Martin Gogov
@blaxter
I tried adding @@@ output.flush @@@ but I got an error @@@ undefined method 'flush' for #<ActionDispatch::Response ...> @@@
Actually format and response seem to be the same object. Isn't this wrong?
I also tried @@@ output.write "Something\n" @@@ but it also didn't flush and returned the response at the end.
I used wireshark to sniff whether any packets are being sent meanwhile and there was no activity before the final response got sent back. I'm using Webrick but I read that I should try Mongrel to make this work so that's what I'm trying now.
Martin
-
Martin Gogov
Sorry for the misformatted previous post.
Just wasted some more hours on checking this:
The self.response_body = proc { |resp, output| ... } approach with mongrel (webrick didn't work) worked almost fine for me (no need to output.flush, there's no such method in my case anyways).
I'm using ruby 1.9.2p35 with rails 3.One side problem I still haven't worked around though is that with this approach the code in the proc gets executed twice so I have to put an if which skips every other execution to avoid double execution.
And still, the resp and output variables point to the same object. No idea why.
Martin
-
John Firebaugh
As Martin alludes to, the proc assigned to
response_bodyis mistakenly executed twice. This is becauseActionDispatch::Responseoverrides#body(defined inRack::Responsewithattr_accessor), and enumerates the body. Thus whenRack::Response#closecallsbody.close, a second execution is triggered.I think that
ActionDispatch::Responseshould not overridebody. If it needs to force a string it should define#body_textor some other method with a name that makes it clear that it disables streaming.On the subject of when or if response data is flushed, as far as I can tell it's entirely up to the Rack handler being used. I can confirm that Mongrel does flush automatically.
-
Rodrigo Rosenfeld Rosas
Maybe we should close this now that 3.1 will support streaming again... What do you think?
