How to add existing file to ZIP file using RubyZIP?
<p>In my Rails 4.2 application I am using <a href="https://github.com/rubyzip/rubyzip" rel="nofollow">RubyZIP</a> to create a controller action similar to the following:</p>

<pre><code>class SomeController &lt; ApplicationController

  def some_action
    file_stream = Zip::ZipOutputStream.write_buffer do |zip|
      zip.put_next_entry "dir1/hello.txt"
      zip.print "Hello"
      zip.put_next_entry "dir2/hello.txt"
      zip.print "World"
    end
    file_stream.rewind
    respond_to do |format|
      format.zip do
        send_data file_stream.read, filename: "zip_file.zip"
      end
    end
  end

end
</code></pre>

<p>In the example two files are dynamically created and written to, then saved into a ZIP file. </p>

<p>But how can I add a file that already exists (!) to the ZIP file as well, e.g. a PDF file from my <code>/app/assets/documents</code> folder?</p>

<p>This should be much easier to achieve but I can't find any documentation on it.</p>

<p>Thanks for any help.</p>