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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I would love to hear more on this as well. Currently suffering in Rails3 due to this not having a clear solution. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Oct 5, 5:33 pm, releod <rel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I would love to hear more on this as well. Currently suffering in > Rails3 due to this not having a clear solution.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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: =========class MainController < ApplicationController def test self.response_body = proc { |resp, out| # you can change this logic here to stream what you want. I tested it with some dynamically generated text. while ... out.write "Sample text" end } end end ========= Only problem with this is that the code in the proc gets executed twice (no idea why), so put an if clause to skip every other execution (: Will be glad to hear how you can solve this. 4) WEBrick didn''t work for me, Mongrel works great. Running Debian, apache2, mongrel, ruby 1.9.2p35, rails3 Martin On Nov 9, 11:29 am, Gogov <mgo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > On Oct 5, 5:33 pm, releod <rel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I would love to hear more on this as well. Currently suffering in > > Rails3 due to this not having a clear solution.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.