I have created a CSV downloader in a controller like this
format.csv do
@records = Model.all
headers['Content-Disposition'] = "attachment; filename=\"products.csv\""
headers['Content-Type'] ||= 'text/csv'
end
Now I want to create server sent events
to download CSV from this for optimising purpose. I know I can do this in Rails using ActionController::Live
but I have have no experience with it.
Can some one explain to me how I can
- Query records as batches
- Add records to
stream
- Handle
sse
from browser side - Write records to CSV files
Correct me if any of my assumptions are wrong. Help me do this in a better way. Thanks.