Developing in Rails 2.1 and deploying in Rails 2.0.2 (or error – undefined method time_zone)

Problem
You are developing on the latest version of Rails (2.1), but your production server for deployment uses version 2.0.2 (as dreamhost is using at the moment).

Solution

  1. First change the environment.rb file to use the rails version in your deployment server
  2. You should probably be geting the error: undefined method = time zone by now, so make sure you comment out from further down your environment.rb file the line:
  3. Some further errors would be caused by the file config/initializers/new_rails_defaults.rb, so make sure you comment out the following lines:

You should be able to deploy and use your application now.

Upgrading to Rails 2.0.2 problems/solutions

Problem
Upgrading from Rails version 1.2.3 to version 2.0.2.
Following the suggestion in DH’s weblog here when using sudo gem install rails -y, it gets the trunk version of rails which at the time was 2.0.2.9216.
This causes a few problems and breaks a few more things.

Solution
In order to get back to the latest stable version, you have to uninstall a few of the gems installed from the trunk version.
If you have installed the latest version of top of an existing one using gems, then doing:

will give you all the installed versions of the gems. Something like:

Make sure you uninstall all the gems with version number 2.0.2.9216:

In each of the above commands the gem package manager should ask you to select the one you want to uninstall.
Pick the one with the 2.0.2.9216 (or other version later than 2.0.2).

At the end if you list the gems again you should only have gems going up to version 2.0.2

An extra step I had to take for making the migrations work was to install rake again:

After all these my installation seems to be working fine again.