Upgrading to Rails 2.0. A Recipe

Share this article

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 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.

Myles EftosMyles Eftos
View Author

Myles a Perth-based web developer who has worked in all the major web languages, his weapon of choice being Ruby on Rails—although he’s found himself doing more and more front-end development in JavaScript, HTML, and CSS.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form