Rails 2 new ways

To get used to the new ways of working with Rails 2.

Here are some of the new ways of doing things in Rails 2.

  1. Create a scaffold and migration on one step:

    Make sure that you don’t have any previous migration(ie manually created) for the same model, as the generator will stop and won’t overwrite the previous migration.

Upgrading Ruby on Rails application from 1.2.3 to 2.0.2

Upgrading an existing Ruby on Rails application from 1.2.3, to 2.0.2, presents few problems. I will try and keep a record of the ones I encounter along the way, here.


  1. Change the config/environment.rb to let the application know to use the 2.0.2 gem rail version,
  2. change the following line from:


  3. Run the following to generate the secret key for the application:
  4. Copy the magic key in a new section in your config/environment.rb as in:

Google Analytics UID

You want to find out your UID for a specific domain that you have set up with google analytics.

When you first create the tracking code for your website, it’s quite obvious how to get the UID for that specific website.
If you decide later on to change your site, from drupal to wordrpess for example, it’s not quite clear where to get this UID, to use it with the new tracking plugin in the new site (which still uses the same domain name).
After some searching it turns out that to be able to find it you have to do the following:

  1. Log in to your Google Analytics Account
  2. Click on the ‘Edit’ link under Settings for the domain you want to find the UID
  3. In the new page click on the link ‘Check Status’ after Receiving Data at the top
  4. Your UID should be in the text box with something like _uacct = “UA-xxxxxxx-x”;

ruby incorrect encoding of pound sign(£)

You want to pass the £ sign to an http service, but the ruby CGI.escape encodes it incorrectly.

After using ruby’s CGI.escape for the string as:

then replace the encoding with the pound sign encoding as in:

It should then pass the correct value for the £ sign.

Disabling rails web site when using mongrel,Apache,capistrano 1.4.1

You want to disable your rails web site for maintenance, but your application uses an older capistrano version than the one currently installed.

According to the RubyOnRails Cookbook recipe 13.12, it should only be a case of running cap disable_web (enable_web).
But in the meantime you have upgraded your capistrano version to version 2, and started using mongrel server as well.
So if you are using virtual severs and proxy with mongrel, the first thing to do is add the following in your Apache configuration file:

If you needed to make the above change then you will have to restart apache in your server.

Then in your local pc you can run the following: