1

my Rails3 Application has a certain request which generates a large CSV (20mb+) on the fly, and then prompts the user to download the file (while it is being generated).

I've noticed while upgrading from Rails 2.3.x using "render :text => proc" no longer works. I am now working on a solution that will let me keep things working in a similar fashion.

The fact that the file is being generated on the fly has not caused any pain just yet. Only certain users, can access this feature (think monthly reports, etc).

I am basically planning on two different approaches, 1. add a custom renderer which will let me use a proc again 2. generate the file in a thread, and use "send_data" to try and stream the file as it is being generated.

I haven't implemented yet, so if anyone can provide some insight, it may help clear things up as the code is upgraded.

Thanks!!!

releod
  • 513
  • 5
  • 12
  • Duplicate of http://stackoverflow.com/questions/3507594/ruby-on-rails-3-streaming-data-through-rails-to-client – John Oct 04 '10 at 18:21

1 Answers1

0

I'm working on a very similar problem, and I decided to fork csv_builder to add streaming support. I have a working prototype version, which has a template handler return a proc rather than a string. Inside the proc, I wire the csv_builder to write to the output stream directly. There are some goofy tricks I had to use to make it work in test and development, because TestResponse's output isn't the full-blown io stream that CSV expects.

take a look: https://github.com/fawce/csv_builder

fawce
  • 822
  • 6
  • 10