I am desperate to get a streaming CSV download working in my Rails 3.2.2 app.
I have tried the 'csv_builder' gem (https://github.com/dasil003/csv_builder), which advertises support for this feature, however it seems that there were some changes in Rails 3.2 that are keeping it from working (it produces an 'uninitialized constant ActionView::Template::Handler' error on app startup).
Any other ideas or solutions out there? Thanks!
EDIT: To clarify, I am needing to export all entries of a model as a CSV file. There are so many rows, that it is timing out... therefore the need for streaming. I have used the Comma gem (https://github.com/crafterm/comma) for this in the past, but it doesn't support streaming either, at the moment.
OK, after a bit more research I hacked together the following in my controller. It'll stream if
response_body
is given something enumeratable (is that a word?). Also, the server needs to be able to stream (I am using Unicorn on Heroku). I'd like very much to not have all this stuff in the controller, so my next step is to extract it out somehow.The approach that I took with a Rails 2.3.8 app was to spawn a new thread to handle the csv parsing and then use an AJAX call to check the server to see if the file was ready (I relied on File.mtime).
Just ripped it out of the app to post here so I've removed alot of the csv parsing code, and haven't included all of the views
sorry end of the day rush :D
controllers/exports_controller.rb
views/exports/export_checker.rjs