0

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

p0k3
  • 333
  • 5
  • 23

2 Answers2

0

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
Martin
  • 7,634
  • 1
  • 20
  • 23
0

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

Prawn shown up PDF generated in browser

Community
  • 1
  • 1
Aravind.HU
  • 9,194
  • 5
  • 38
  • 50