Why freeze when you can symlink

Just a quick thought: for a while now, I’ve been putting this in my Capistrano recipe, in the :after_update_code task:

run "cd #{release_path} && rake rails:freeze:edge TAG=rel_1-2-4"

But what’s the point in exporting the same 5Mb of files every time you deploy? Instead, let’s do this:

run "ln -s #{release_path}/../../shared/rails/1.2.4
    #{release_path}/vendor/rails"

cd into your Capitrano shared directory on your server, and run

mkdir rails
cd rails
svn export http://svn.rubyonrails.org/rails/tags/rel_1-2-4 1.2.4

Do that for as many versions as you want to keep handy, and you’re all set. Every time you deploy, your app will contain a link to one of your local copies of Rails. No more waiting around for Rails to export.

This also has the advantage that it doesn’t matter what version of Rails your host has installed, as you’re not running a Rails rake task any more. When using rails:freeze:edge, the server will try to find that task in the version of Rails specified by RAILS_GEM_VERSION in environment.rb. If you use a symlink, it doesn’t matter whether your Rails version is installed or not. The version you link to can then be used to run subsequent rake tasks.

If you’ve enjoyed this article, you might enjoy my recently published book JavaScript Testing Recipes. It’s full of simple techniques for writing modular, maintainable JavaScript apps in the browser and on the server.