Generating file for download from controller method on demand

Hello

I'd like to implement in my app functionality of generating text files for download (like excel files etc.) generated on demand (user clicks "download a copy" and rails app should generate it and let user download, or at least start downloading by user)

Is there any possibility to do it as simple as possible? :slight_smile:

Best regards and thank you in advance for your responds Pawel K.

that's my controller code for downloading a pdf file generated in the method write_invoice_pdf with pdf-writer

def pdf   write_invoice_pdf   send_file(File.join(PDF_PATH_INVOICES, "result.pdf"), :filename => 'result.pdf', :disposition => 'attachment', :type => 'application/pdf') end

that's basically all to it. generate the file, store it 'somewhere', PDF_PATH_INVOICES in that case defines the target folder and is set in development.rb. after that it needs only to be sent and the browser will open the dialog to ask if you want to open it or save to disk.