title: Rails send multiple files to browser using send_data or send_file
body: <p>I am trying to send multiple files to the browser. I cant call send_data for every record like in the code below because i get a double render error. According to <a href="https://stackoverflow.com/questions/8053496/rails-using-send-file-to-send-multiple-files">this post</a> i need to create the files and zip them so i can send them in one request.</p>
  
  <pre><code>@records.each do |r|
    ActiveRecord::Base.include_root_in_json = true
    @json = r.to_json
    a = ActiveSupport::MessageEncryptor.new(Rails.application.config.secret_token)
    @json_encrypted = a.encrypt_and_sign(@json)
    send_data @json_encrypted, :filename =&gt; "#{r.name}.json" }
  end
  </code></pre>
  
  <p>I am creating an array of hashes with the <code>@json_encrypted</code> and the <code>file_name</code> for each record. My question is how can i create a file for every record and then bundle them into a zip file to then pass that zip file to <code>send_file</code>. Or better yet have multiple file download dialogs pop up on the screen. One for each file.</p>
  
  <pre><code>file_data = []
  @records.each do |r|
      ActiveRecord::Base.include_root_in_json = true
      @json = r.to_json
      a = ActiveSupport::MessageEncryptor.new(Rails.application.config.secret_token)
      @json_encrypted = a.encrypt_and_sign(@json)
      file_data &lt;&lt; { json_encrypted: @json_encrypted, filename: "#{r.name}.json" }
  end
  </code></pre>