Rails Exporting to CSV without constructing CSV in memory -
rails 2.3.5, ruby 1.8.7.
in prior question, there number of solutions exporting data in csv format, of them seem construct data in memory before sending. wise when exporting large data sets? of solutions in prior question avoid this.
or impossible avoid building response without building whole response locally, either in memory or in temp file?
i not surprised if latter true, since if there error in csv generation, might want send error message instead, might generating way data want generate data in memory/on disk.
you can stream directly csv library (fastercsv in ruby 1.8).
render :text => proc { |response, output| csv.generate(output) |csv| csv << ... end } you should use find_in_batches if concerned memory footprint.
Comments
Post a Comment