Hi I have created csv file
, I want to download that file in .zip-file
in my rails application. Please help me. I am not able do this how to add that file to zip and download that zip-file. How to render that file in rails.
Below is the piece of code which I have tried,
# method to create csv
def to_csv
CSV.generate do |csv|
#build csv format of document
end
end
# controller action to download zip
def zip_download
zip = Zip::File.open('document.zip', Zip::File::CREATE) do |zipfile|
@documents.each do |document|
# document.to_csv how to add this file .zip
end
end
send_data zip, filename: "abc.zip", type: 'application/zip'
end