Upgrading to Rails 2.0. A Recipe

In previous posts, I’m covered some of the updates to Rails 2.0 and how to prepare for Rails 2.0 but haven’t really covered the mechanics of HOW to upgrade to Rails 2.0. So as part of the 6 things to try in Rails this year series, I have compiled a quick recipe that works for me. It probably isn’t the only method, but it works.

1. Fix all of the deprecated warnings

The easiest way to do this is to download Geoffrey Grosenbach’s rake task that I previously mentioned. Copy it to the lib/tasks directory of the app you want to upgrade and run


rake deprecated

This will point you in the direction of any deprecated methods. Find them and fix them.

2. Cleanup your environment

I used to put a lot of code in the enviroment.rb file, which is really a bit of a no-no. To facilitate this, the Rails team introduced the initializers directory where you can add custom code that is automatically loaded at run time. You will need to create the directory now, so run


mkdir config/initializers

Create a new ruby file under that directory and move any custom code, mime types and inflectors from the enviroment.rb files.

3. Update the engine

Even though a lot of the Rails engine is provided by the Rails gems, there is some boiler plate code that each app needs. This is created when you run the rails /path/to/app command. Well, to ensure that everything is up to date, we will do the same thing again. The rails command is smart enough to compare files for differences before overwriting them.


rails /path/to/your/app

You should now be asked “overwrite [file]? (enter “h” for help) [Ynaqdh]” for a whole bunch of files. Double check each filename before hitting yes – some of the files you WON’T want to overwrite (Examples are 404.html, 500.html, database.yml etc). If it is a configuration file you probably won’t want to overwrite it. It will also update the JavaScript libraries, so if you are reliant on those, you may want to say no there too.

I’ve found this is the best way to make sure everything is up to date.

4. Update the views

Whilst not strictly required, I found a rake task in this article that renames .rhtml files to .html.erb which is nice for consistency.

For a standard Rails install that doesn’t use any of the deprecated plugins, that should be it! Let me know if you find any other tidbits of wisdom.

Win an Annual Membership to Learnable,

SitePoint's Learning Platform

  • http://www.sitepoint.com/ mattymcg

    Nice one Myles. I have been going the hard way — creating a new app then pulling bits and pieces across until it works. I think this is probably a safer bet. That view-renaming rake task is gold!

  • Anonymous

    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

    Alena

    http://www.smallbusinessavenues.com