daustin777
daustin777

Reputation: 12748

Need user to be able to download 2 files consecutively in a ruby on rails app

What is the best way to handle the need to a user to download 2 files. I'm using send_data to send the file to the browser. How can I allow the user to get two dynamically generated files from one request, OR what is a better alternative to do this. A simple example of what I'm trying to do is:

  def data_out
    output = "foo foo foo "
    send_data(output,:type => "text/csv",:filename => "foo.txt")

    output2 = "bar bar bar"
    send_data(output2,:type => "text/csv",:filename => "bar.txt" )
  end

When calling data_out, only bar.txt file is sent to the browser.

Upvotes: 1

Views: 192

Answers (2)

Matt Darby
Matt Darby

Reputation: 6324

I would zip them first using RubyZip, then present the zip file as a single download. Smaller download size, faster download.

Upvotes: 3

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

Call each one from a hidden iframe.

You can add an iframe to the DOM with this file as its src.

Upvotes: 2

Related Questions