Özgün Koyun Özgün Koyun

Upgrading your rails app from 1.2.x to 2.1.x


These are the steps I followed while upgrading 2 of my rails applications. One of them was developed with Rails 1.2.2 and the other was 1.2.3. They are not complicated apps, so my job here was easy. If you have a sophisticated application you may need to work a little bit harder.

First of all, backup your rails app, in case something bad happens!

$ cp -r myapp myapp.backup

Backup your database.

$ mysqldump -u username -ppassword db_development > db_development.sql
$ mysqldump -u username -ppassword db_production > db_production.sql

Dive into your old applicaiton and remove all session files.

$ cd myapp
$ cd tmp/sessions
$ find . -name "*_sess*" -exec rm '{}' \;

Update RAILS_GEM_VERSION in your config/environment.rb file.

RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION

Update your rails app.

$ cd myapp
$ rake rails:update

Install necessary plugins. With Rails 2.x some integrated features turned to plugins such as acts_as tree, acts_as_list..

$ cd myapp
$ ./script/plugin install acts_as_tree
$ ./script/plugin install acts_as_list

Add secret key to your config/environment.rb file.

config.action_controller.session = { 
    :session_key => "_myapp_session", 
    :secret => "your secret here .. don't tell anyone" 

Install classic_pagination plugin if you used pagination in your application. The official source for this plugin should be svn://errtheblog.com/svn/plugins/classic_pagination. However, this url is unreachable. So we are going to try another workaround to install it.

$ cd myapp
$ cd vendor/plugins
$ git clone git://github.com/masterkain/classic_pagination.git

Find and replace all find_all with find(:all). To find out:

$ cd myapp
$ grep find_all * -r

If you used start_form_tag and end_form_tag in you app, you should add 2 methods to application helper. If you don’t want to add these 2 methods, then you should convert your forms to code block. Check out this google group discussion for more info.

$ cd myapp
$ vim app/helpers/application.helper
def start_form_tag(*args)
def end_form_tag

I’ve realized that I didn’t use RAILS_ROOT in my application while setting file or directory paths. Rails 1.2.x version didn’t complain about that, however, Rails 2.x complains about not finding directory paths. I solved this issue by using RAILS_ROOT while creating directory or file paths. If you have file uploads in your application, I suggest you look over your codes.

Show time! Start your application server and test with your browser. I know you run Firefox

$ ./script/server

This is how I managed to work my old rails app work in Rails 2.1.2. They are not very complicated apps, so it was easy to switch to Rails 2.1.2. If you want to add something to my list please be my guest. Thanks!