Rails Zip download

Zip package

Use rubyzip Git hub
Gem package has this library. You need to add

# Zip
gem 'rubyzip', '~> 1.1.6'

Sample(Controller)

def generate
  filename = "file.zip"
  temp_file = Tempfile.new(filename)
  begin
    Zip::OutputStream.open(temp_file) { |zos| }
    Zip::File.open(temp_file.path, Zip::File::CREATE) do |zip_file|
      #put files in here
      infile = Tempfile.new("test.txt")  
      zip_file.add("test.txt", infile.path)
    end
    zip_data = File.read(temp_file.path)
    send_data(zip_data, :type => 'application/zip', :filename => filename)
  ensure
      temp_file.close
      temp_file.unlink
  end
end

I also use Tempfile

Ref

THINK IN GEEK