Following the previous post, I decided to spin off a little ruby gem for you folks. Get streamy_csv, and write only your application code while it’ll do the boilerplate work for you.
In a nutshell, with this gem in your application, all you need to do is this:
Class ExportsController
def index
stream_csv('data.csv', MyModel.header_row) do |rows|
MyModel.find_each do |my_model|
rows << my_model.to_csv_row
end
end
end
end
Find more at https://github.com/smsohan/streamy_csv