Forum: Ruby on Rails Streaming from controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aaafe7b4a583540a3042f643a97177bf?d=identicon&s=25 white@ (Guest)
on 2009-05-14 09:42
(Received via mailing list)
Hi people,

I need to stream a lot of data from the controller (no need for a
view). It generates on the go, and can take pretty long time to
complete.  I'm not sure it effective to generate a string (the output
can be hundreds of megs) and pass it to the view.

However, the only way I found is to use render :text => ... which also
can be called only once in controller, so not a real on the go
streaming.

Neither store to file and then streaming it with render :file works.
Several simultaneous uses of the controller can generate pretty huge
files for every instance, which is no-go.  Anyway, it's not on the go
as well.

The other way is render :text = Proc.new { |r,o| ... }, however,
somehow it doesn't seem to be working for my case.  First of all, it
complains about some random each ... do blocks (which work just fine
when the blocks are not passed to Proc.new).   When I'm commenting
them out, I'm getting things like that:

Wed May 13 17:34:39 -0700 2009: Read error: #<ArgumentError: A copy of
DoController has been removed from the module tree but is still active!
>
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/
dependencies.rb:414:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/
dependencies.rb:96:in `const_missing'
/Users/white/repo/vurvimport/app/controllers/do_controller.rb:380:in
`preparesql'
/Users/white/repo/vurvimport/app/controllers/do_controller.rb:630:in
`rendersql'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
response.rb:153:in `call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
response.rb:153:in `each'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/chunked.rb:37:in `each'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/handler/mongrel.rb:74:in `process'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
`process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
`process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/handler/mongrel.rb:34:in `run'
/Library/Ruby/Gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3

I think the similar situation is also mentioned here
https://rails.lighthouseapp.com/projects/8994/tick...

So, I'd very appreciate any hint how I can solve this problem.  Thank
you.
This topic is locked and can not be replied to.