I am using rubyzip
with rails 4
and I am trying to make a custom method to download all the attachments in the submission table without phisically creating the zip file.
submissions_controller.rb
def download
@submissions = Submission.all
file = "#{Rails.root}/tmp/archive.zip"
Zip::ZipFile.open(file, Zip::ZipFile::CREATE) do |zipfile|
@submissions.each do |filename|
zipfile.add(file, filename.file.url(:original, false))
end
end
zip_data = File.read(file)
send_data(zip_data, :type => 'application/zip', :filename => "All submissions")
end
How can I set the file var right. The documentation says that that is the archive name, but I do not want to create that physical archive. Maybe just as a tmp ?