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