Rails - pdfkit/pdfkit GitHub Wiki
How to cache the PDF using Rails page caching and PDFKit
-
Disable the PDFKit middleware so that your controller handles the generation of the PDF.
-
Register PDF as a mime-type in environment.rb
Mime::Type.register "application/pdf", :pdf -
In your controller, cache pages just like normal with
caches_page :show -
create a format.pdf call in your respond_to block and init a new PDFKit object, pass in the url to the current action and call
to_pdfon it.respond_to do |format| format.html # show.html.erb format.pdf { render :text => PDFKit.new( post_url(@post) ).to_pdf } end
Now in your cache directory you'll create two cache files - one .html and one .pdf.