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.
(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
def download_quote
pdf = QuotesPdf.new(params)
send_data pdf.render, filename: "foo.pdf",
type: "application/pdf",
disposition: "download"
end
Then I have a button in my HTML view that has this working Jscript code
// AJAX, download
function ajaxRequest(){
$.ajax({
type: 'POST',
url: '/download_quote/126',
success: function(data){
alert(data);
}
});
return false;
}
$("#mydownload").click(ajaxRequest);
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.
Question is: How can I transform data in a pdf file and automatically download it?