Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

How To Vendor Rails

Today I was bitten by the incompatibility of Rack 1.0.0, Passenger 2.2.1, and Rails 2.3.2.1:

  undefined method `new' for "Rack::Lock":String (NoMethodError)

Since I had already (inadvertently) upgraded Rack, the solution was to upgrade both Passenger and Rails.

Upgrading Passenger to 2.2.2 was straightforward. Just remember to update the paths in your passenger.conf to point to the 2.2.2 version.

Upgrading Rails wasn’t quite as straightforward because the compatibility fixes aren’t yet available in the Rails gem. Instead we have to run our application against the latest stable branch, 2-3-stable.

To do this I vendored Rails as a Git submodule. This is nothing new but it’s the first time I’ve needed to do it.

$ git submodule add git://github.com/rails/rails.git vendor/rails
$ git commit -m "Vendored Rails edge as a submodule."

This got me running on edge Rails. To run on the 2-3-stable branch I then did:

$ cd vendor/rails/
$ git checkout origin/2-3-stable
$ cd ../..
$ git add vendor/rails
$ git commit -m "Pinned Rails to branch 2-3-stable as of 4b68deb."

Thanks to Graeme Mathieson, Ariejan de Vroom, Daniel Morrison and August Lilleaas for their helpful articles.

Locally this all worked fine but on deployment the vendor/rails directory wasn’t populated due to the way submodules work. You have to initialise and update them each time; happily Capistrano supports this with:

set :gitenablesubmodules, true

At this stage it’s a good idea to use a remote cache:

set :deployvia, :remotecache

As and when I go back to running Rails from gems, I’ll remove references to the submodule in .gitmodules and .git/config, and then do:

$ git rm --cached vendor/rails

Thanks to Jose Cedeno via GitHub Guides.

Finally my application ran again and I could return to working on it rather than the infrastructure…

Comments

Hey,

Thanks for the post. I spent a good 20 minutes trying to troubleshoot the rack error… didn’t even put 2 and 2 together that I had updated passenger without fixing the apache.conf file. Thanks very much for an enlightening post!

All the best,

Kent

Kent Fenwick • 1 June 2009

Andrew Stewart • 28 April 2009 • RailsDeployment
You can reach me by email or on Twitter.