A collection of computer systems and programming tips that you may find useful.
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Tuesday, June 17, 2008

Using Older Versions of Rails

You want to develop with the latest version of Rails but you have an existing application that
uses an older version that you are not ready to bring up to date. What do you do?

By default gem will keep older versions of installed gems until you tell it not to. To see what you have installed:
$ gem list --local
rails (2.1.0, 1.2.3, 1.2.1)

To use a specific version in your application add a line like this to the bottom of your config/environment.rb file

That should just work.

You can get rid of old versions of gems with this command:
$ gem cleanup

If you remove an old version by mistake you can always reinstall it with this gem command:
$ sudo gem install rails --version 1.2.3

When you are ready to move your application to the current version of rails then remove the line from environment.rb and bring your application files up to date with:
$ rake rails:update

Now, let's say you have installed the current version of Rails (say, 2.1.0) but you need to build an application that uses an older version. According to 'rails --help' there is no way to specify a version to use. It turns out that there is a hidden option available that does this:
$ rails _1.2.6_ myapp

Simple! Why this isn't explicitly documented I don't know. I found out about it from this post: http://rubybook.ca/2008/08/06/downgrade-older-version-rails/. Obviously you need to have the older version of Rails available on your system.


geo1004 said...

Actually, to generate a rails application with a specific version the command is rails _numberOfVersion_ new app_name. You just forget the "new".
So for example to generate an application "MyApp", with rails version 3.0.3 you have to do : rails _3.0.3_ new MyApp.


klairvoyant info solutions said...

geo1004 commend help he in a critical time

Archive of Tips