0

I would like to create 2 pdf documents from a single click.

I have it working with one file, but I can't seem to get to make 2 download files to happen w/out browser complaining about DoubleRenderError.

This is the code in my controller, where I am calling it twice and breaks. If I do it just once, everything works fine.

    respond_to do |format|
        format.pdf do
            pdf = PrintCardsFront.new(paperSize, cardCount, @cards)
            send_data pdf.render, filename: "cards_front_side.pdf", type: "application/pdf"

            pdf = PrintCardsBack.new(paperSize, cardCount, @cards)
            send_data pdf.render, filename: "cards_backside_side.pdf", type: "application/pdf"
        end
    end

(Rails 4.2)

Michael
  • 119
  • 1
  • 13
  • Check this one http://stackoverflow.com/questions/2339440/download-multiple-files-with-a-single-action – Nadiya Aug 30 '16 at 06:40

1 Answers1

0

You can only send one file in the HTTP Protocol.

Try to zip your two files and send them to the user.

Chris
  • 1,008
  • 2
  • 11
  • 22