Добавить в Gemfile gem 'rubyzip'
.
#foo model
...
has_many :uploads
...
#foo controller
def download
@foo = Foo.find(params[:id])
unless @foo.uploads.empty?
send_file Upload.zip(@foo),
:type => 'application/zip',
:disposition => 'attachment',
:filename => "Foo-#{@foo.id}.zip"
end
end
#Upload model
def self.zip foo
archive = File.join("public", "files", foo.id.to_s, foo.id.to_s) +".zip"
unless File.exist? archive
files = foo.uploads.all
Zip::ZipFile.open(archive, 'w') do |zip_file|
files.each do |foo_file|
zip_file.add(foo_file.upload_file_name,foo_file.upload.path)
end
end
end
archive
end