Migrating to Rails 2.0


Rails 2.0 was released in December, 2007. For those enthusiastic few who want to upgrade their projects to 2.0, be forewarned–it’s not a push-button upgrade. There are a few “gotchas” along the way.

Updating your Rails is not for the weak. It is entirely possible that you will “hose” your entire development environment and that you’ll need to reinstall. If you don’t have any problems with that, read on!

The first thing you want to do is upgrade your system’s Rails to 2.0 via the following commands:
gem install rails -y
gem update --system

Once that’s done, you have Rails 2.0 in your system! Go ahead and change RAILS_GEM_VERSION in your environment.rb file to reflect the Rails version you have (eg. 2.0.2).

Next, run rake secret from the command line to generate a unique key for your application. Add this block into your environment.rb file:

config.action_controller.session = {
:session_key => '_YourApplicationName_session',
:secret => 'your secret key goes here'
}

You’re almost there! Your application should launch–but if you request any views, Rails will inform you that it can’t find the templates! To understand why, we’ll diverge momentarily into a discussion of scaffolding.

As of Rails 2.0, you need to generate scaffolding (”static scaffolding” in Rails 1.2) if you want to use scaffolding code–you can no longer write scaffold :model_name in your controllers. You can, however, generate a model, controller, and views with a single line–including relevant edit and new forms–via the new scaffold:

script/generate scaffold <model name> <model fields>

… where your model fields is a list of the fields the model uses. (These plug into the new/edit forms.)

If you do this, you’ll notice the new scaffold generates *.html.erb files instead of *.rhtml files; once you specify that your application is using Rails 2.0, it’ll look for .html.erb instead of .rhtml. That’s why it crashes–simply rename the files, and you’re ready to go!

Finally, be aware that if you use @params and @request (which were deprecated), your code will no longer compile. Use params and request, and your code should compile.

If you’ve run into any other upgrade issues, post them in the comments.

Tags: ,     Posted in Development

Rate this article:
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3 out of 5)
Loading ... Loading ...

Related Content


One Response to “Migrating to Rails 2.0”

  1. Upgrading to Rails 2.1 on Windows « Chronicling My Ruby on Rails Journey Says:

    [...] different articles have slightly different ways of doing the upgrade. According to this article Migrating to Rails 2.0, it suggested the following commands (it’s the one I ended up following): gem install rails [...]

Leave a Reply