I recently upgraded one of my apps from Rails 2.2.2 to Rails 2.3.2. It was actually a really easy upgrade, but there were few little gotchas I had to watch out for, so I thought I’d share my experience.
Upgrading Rails
I imagine there is probably a better way to do this, but since I change the version of rails so infrequently I’m not sure. (If there is a better way, please let me know). My flow is as follows:
Install the new version of the rails gems:
sudo gem install rails
Branch your app
git branch newrails
git co newrails
Remove the old version of frozen gems
git rm -rf vendor/rails
Update your config/environment.rb file to the new version of rails:
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
freeze the new gems
rake rails:freeze:gems
Please note, that if instead of installing the new gems and freezing them from your local gems, it looks as though you need to be careful if using rake rails:freeze:gems. You can read more about it in the official post or in this post which I found more understandable.
Testing Your App
The first and most obvious error you will run into is this:
uninitialized constant ApplicationController
This is because as of Rails 2.3 application.rb is now application_controller.rb. To fix this just do
git mv app/controllers/application.rb app/controllers/application_controller.rb
The next error I got was
undefined method `relative_url_root' for #
I narrowed this down to a stylesheet_link_tag call. I got around this by updating the asset_packager plugin, and updating HAML to 2.0.9. By the way, if you’re not using asset packager, you should be.
That’s it! It overall was a very easy upgrade that took much less time to test than my rails 2.1 to rails 2.2.2 upgrade.
Here are some other rails 2.3 gotchas to watch out for courtesy of thoughtbot.