Unable to freeze rails due to problem in rake task

I think the current version of stable Rails is 1.2.3. For those of you using this version, rather than Edge Rails, there’s a little gotcha in the rake tasks.

Since I’m on a shared host, it’s good practice to freeze your version of rails into the vendor’s directory. You do this by using a rake task, per “rake rails:freeze:gems” But before you do that, if you’re using SVN, you’ll want to use “svn delete” to remove the vendors/rails directory. None of the rake tasks use SVN delete. They all use “rm -rf”, which in my experience makes SVN freak out if the .svn directory is gone.

However, even with that done, freezing a new version of gems was failing.

It was looking for rails version 1.4.0, and not being able to install it. And even worse, when you try to run rake again, it said it couldn’t find it!

Well, the latter was simple. A failed freeze leaves a blank vendor/rails directory, and if you look in ‘config/boot.rb’, it says:

if File.directory?("#{RAILS_ROOT}/vendor/rails")
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
else
require 'rubygems'
...blah blah blah..

So make sure you remove vendor/rails.

The latter took a little bit of work digging around the rake tasks, and though it wasn’t hard, I wasted about an hour. It ends up that the culprit is that the default rake task uses Gem.cache.search(‘rails’), which returns all gems with the name ‘rails’ in it.

I have a couple gems installed with the word ‘rails’ in it.

rails (1.2.3, 1.2.0, 1.1.6)
rails_analyzer_tools (1.4.0)
railsbench (0.9.2)

So it took the latest one, which was 1.4.0, and tried to install rails 1.4.0, which doesn’t exist!

To hot fix it, the railities/lib/tasks/framework.rake file, under the freeze namespace and gems task, change “Gem.cache.search” to “Gem.cache.find_name”

That way, it only finds ‘rails’, and not all the other games with ‘rails’ in the name of the gem. This problem is solved in edge Rails, so no need to submit a patch. Tip!

Advertisements

2 thoughts on “Unable to freeze rails due to problem in rake task

  1. Thanks, this helped me out. I was using Aptana and had a problem trying to commit my change after freezing gems and figured out what the problem was, but not how to prevent it, and this worked perfectly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s