PDFKit middleware problem on Rails 2.3.8-Collection of common programming errors

I have installed PDFKit and wkhtmltopdf on my Ubuntu 8.04 server. I am trying to use PDFKit as middleware in my Rails 2.3.8 app and have added the following lines to environment.rb (as directed on the jdpace pdfkit page):

require ‘pdfkit’ config.middleware.use PDFKit::Middleware

My Mongrel seems to start up but as soon as I request a page the following error appears in the Mongrel log:

** Writing PID file to tmp/pids/mongrel.9270.pid /!\ FAILSAFE /!\ Tue Sep 07 16:42:20 +0000 2010 Status: 500 Internal Server Error undefined method match' for nil:NilClass /usr/lib/ruby/gems/1.8/gems/pdfkit-0.4.6/lib/pdfkit/middleware.rb:12:incall’ /home/rails/livetest-carbon-hub/releases/20100907133547/vendor/rails/actionpack/lib/action_controller/string_coercion.rb:25:in call' /usr/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/head.rb:9:incall’ /usr/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call’

Has anybody else come across this ?

Any help or suggestions gratefully received !

  1. require ‘pdfkit’ needs to be above the

    Rails::Initializer.run do |config|

    and

    config.middleware.use PDFKit::Middleware

    needs to be underneath, inside the run block.

    You probably also want to add

    config.gem ‘pdfkit’

    and

    Mime::Type.register ‘application/pdf’, :pdf

    in there as well.

Originally posted 2013-11-27 05:07:13.