CNK's blog

Upgrading From Rails 2.3.5 Part 1

Upgrading old software is often painful - but it is especially painful if you wait for a long time so that there are LOTS of changes between the old and new. The main thing that had prevented me upgrading before was a direct connection from my Rails CMS to a legacy Oracle 8i database. I no longer need to do that, so perhaps it is time to catch up with modern Rails.

There are a lot of blog posts about upgrading from Rails 2 to Rails 3; one of the most useful seems to be this one from Simon Carletti that was written before Rails 3 actually came out: The Road to Rails 3: make your Rails 2.3 project more Rails 3 oriented

His recommended first step is to get your Rails 2.3 app running using Bundler to manage your dependencies. The bundler web site has a page on how to use bundler with Rails 2.3 Seems fairly straightforward so I made the adjustments in the Rails boot files and moved my “config.gem” lines from the environment files into a Gemfile. One thing that had been kind of odd in my original project is that Shoulda, my favorite testing tool, would only seem to work if I required it globally, e.g. in config/environment.rb rather than in config/environments/test.rb. Since I am trying to change only one thing at a time, I put shoulda in the global part of my Gemfile and not just in a test section.

Which ruby?

OK so now that I have a Gemfile, which ruby should I try installing it in. Ruby 1.8.7 has had its last feature release and everyone has moved on to Ruby 1.9.3, which should be backwards compatible with Rails 2.3.5. Since that is the only ruby I currently have installed in RVM on my Lion laptop, let’s start with that one. I created a gemset (and an .rvmrc file) and then did ‘bundle install’. I had to do a little fiddling with versions, etc. Some things I knew wouldn’t work with the newer version, for example rails and shoulda. Others I didn’t know but guessed that if there had been more than a couple of minor version updates since the versions I am running in production, the new versions probably wouldn’t work with my older code. So I was fairly aggressive in specifying exactly which versions to use.

Once I had a promising looking Gemfile and installed gems, I tried running the rails console - and then one of the stock rake tasks. Sadly both failed. The script/console error is:

(brazen:~/rails/empcms2.3.5) $ script/console
`require': cannot load such file -- script/../config/boot (LoadError)
    from script/console:2:in `<main>'

And the rake error is:

(brazen:~/rails/empcms2.3.5) $ rake db:schema:dump
rake db:schema:dump
WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
rake aborted!
undefined local variable or method `version_requirements' for

Tasks: TOP => db:schema:dump => environment
(See full trace by running task with --trace)

The rdoc warning is harmless (though annoying) - the alumni code running 2.3.14 is running fine despite similar warnings - but the others are showstopping.

There are some differences between where Ruby 1.8.7 and 1.9.3 will search for files when you ‘require’ or ‘load’ them. I am not sure if that is the cause of the problems I had, but I decided that perhaps upgrading one thing at a time might be the better part of valor. Let’s try falling back to Ruby 1.8.7.

Ruby 1.8.7

Unfortunately I can’t install ruby 1.8.7 on this Lion laptop - or at least not without a lot of work:

$ rvm install 1.8.7
rvm install 1.8.7
The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet
fully supported by ruby and gems, please read `rvm re\
[11:56 PM] (brazen:~/rails/empcms2.3.5) $ rvm requirements
rvm requirements

  Notes for Mac OS X 10.7.4, Xcode 4.3.3.

For MacRuby: Install LLVM first.

For JRuby:  Install the JDK. See  # Current Java version "1.6.0_26"
For IronRuby: Install Mono >= 2.6
For Ruby 1.9.3: Install libksba # If using Homebrew, 'brew install libksba'

You can use & download osx-gcc-installer: ** NOTE: Currently,
Node.js is having issues building with osx-gcc-installer. The only fix
is to install Xcode over osx-gcc-installer.

We had reports of making things work, but
it looks like not easiest/safest to setup.

To use an RVM installed Ruby as default, instead of the system ruby:

rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm
gemset import system.gems # migrate your gems
rvm alias create default 1.8.7

And reopen your terminal windows.

Xcode 4.2:
 * is only supported by ruby 1.9.3+
 * it breaks gems with native extensions, especially DB drivers.

Xcode 4.3+ users
- please be warned
- only ruby-1.9.3-p125+ is partially supported
- in case of any compilation issues:
 * downgrade to Xcode 4.1
 * uninstall Xcode and install osx-gcc-installer
and reinstall your rubies.

Trying to install REE gives a similar message about not liking my gcc compiler. It suggests installing “osx-gcc-installer”.

I don’t love the advice about downgrading Xcode - especially with the other note about osx-gcc-installer not playing well with Node.js. I am not currently using Node.js - but I am interested in trying it. So let’s do this on Linux.


I already have RVM and Ruby 1.8.7p352 installed on the VPS I share with friends. So I tarred up and moved the code from my Mac to that server. Altered the .rvmrc to create a gemset for ruby 1.8.7 and rails 2.3.5. I did not have bundler in that ruby so I installed it into the gemset by hand - and then did “bundle install to get the rest

gem install bundler
bundle install

Looks fine - but I need to configure my database. It is getting late. Take that up tomorrow.