title: Download file data with AJAX request - ruby on rails 3
body: <p>I recently learned that I can't download more than 1 file with a single HTTP request in ruby on rails except I do it with AJAX request. I'm now trying to figure out how to do that.</p>
  
  <p>(I'm using Prawn as PDF creator with Ruby on RAils 3)
  I have an action in my controller that render a PDF and use send_data</p>
  
  <pre><code>def download_quote          
  pdf = QuotesPdf.new(params)
  send_data pdf.render, filename: "foo.pdf",
                      type: "application/pdf",
                      disposition: "download"
  end
  </code></pre>
  
  <p>Then I have a button in my HTML view that has this working Jscript code</p>
  
  <pre><code>// AJAX, download
  function ajaxRequest(){
      $.ajax({
        type: 'POST',
        url: '/download_quote/126',
        success: function(data){
          alert(data);
        }
      });
      return false;
    }
  
    $("#mydownload").click(ajaxRequest);
  </code></pre>
  
  <p>When I click "#mydownload" after few seconds took for rendering PDF, I receive a successful alertbox with inside data, I think, all the PDF file.</p>
  
  <p>Question is: How can I transform data in a pdf file and automatically download it?</p>