I really ran into this problem. Seeing this question, I went deeper into the problem. its a bit complicated, but pdfkit actually lets you know at least one of the ways that .pdf is requested. this can probably use some cleanup, but this is what we are currently doing:
respond_with @object do |wants| wants.html { if request.env["Rack-Middleware-PDFKit"] pdf_page = render_to_string :layout => "print_out" send_data pdf_page, :filename => "file.pdf" else render :layout => "print_out" end } end
source share