I Have a model called Magazine with a number and a pdf file.
I try to access this url /magazine/:number.pdf
In my controller I do :
@magazine = Magazine.find_by_number params[:number]
But How can I display the PDF ?
Thanks
In your controller:
respond_to do |format|
...
format.pdf do
pdf = Prawn::Document.new # don't know exactly how your document is stored
send_data pdf.render, filename: 'report.pdf', type: 'application/pdf'
end
end
Don't forget to register the MimeType too in an initializer:
Mime::Type.register "application/pdf", :pdf
Assuming yours is an MVC application and you are using some web framework like Rails ,
send_data pdf.render, :filename => "filename.pdf", :type => "application/pdf"
References