Patching Rails Edge to stay bug free

Manfred Stienstra

A lot of people are on Rails Edge nowadays. Besides all the nifty new features they also encounter bugs. There are two ways to work around these bugs:

  1. Lock your Rails external to an older revision or freeze it to vendor
  2. Find a patch on Trac or write one of your own and apply it

If you decide to apply patches, you’re going to need some help. Our solution is to put all the patches that need to be applied in vendor/patches and put the following Rake task in lib/tasks/patches.rake:

task :patch => 'patches:apply'

namespace :patches do
  desc "Apply all patches from vendor/patches to root"
  task :apply do
    Dir.chdir(RAILS_ROOT) do
      Dir["vendor/patches/*"].each do |patch|
        system "patch -p0 < \"#{patch}\""
      end
    end
  end

  desc "Revert all patches applied in vendor/plugins and vendor/rails" +
       "through SVN"
  task :revert do
    system "svn revert --recursive vendor/plugins vendor/rails"
  end
end

Assuming you’re using Capistrano 2, you can add the following to your deployment recipe to automatically run the patches for each deployment.

after "deploy:update_code", "deploy:patch"

namespace :deploy do
  task :patch, :roles => :app do
    run "rake patches:apply"
  end
end

Now all you have to do is make sure that all the patches apply cleanly and remove them when they’re accepted into Rails.


You’re reading an archived weblog post that was originally published on our website.