Today I wanted to try how easy it would be to upgrade our existing ShoutSMS (pretty small) rails application from 2.3.8 to latest Rails 3 release candidate (currently rc3). Without taking our test suite into consideration it took around five minutes with help from the official rails_upgrade plugin. This is fast, yes, but considering the size of this app and possible pitfalls I am not looking forward to upgrade our larger projects.
These are the basic steps to perform
- Install rails_upgrade in my 2.3.8 project using “./script/plugin install http://github.com/rails/rails_upgrade”
- Run rake tasks installed with plugin to check what steps are required with “rake rails:upgrade:check”
- Run “rake rails:upgrade:backup” to backup some files which will be override shortly
- Run “rake rails:upgrade:configuration >> upgrade_configuration”
- Run “rake rails:upgrade:gems >> upgrade_gems”
- Run “rake rails:upgrade:routes >> upgrade_routes”
- Create new Rails 3 app above your existing one with “rails n .”
- Check each of your files before overriding – not all are backed up with the backup task
- Copy back in your changes and refer to the three “upgrade_*” files for updated configuration, gems and routes syntax
This did most of the work for me. I needed to patch a bit in my new “application.rb” file (e.g. replace RAILS_ROOT with Rails.root, RAILS_ENV with Rails.env, etc).
Notice, the rails_upgrade plugin might suggest to change “
<% @object.each do |p| %>” blocks to “
<%= @object.each do |p| %>” but I don’t see this should be done.
I needed to upgrade ActiveMerchant but it was a simple
$ gem update activemerchant
and then patch my Gemfile with correct version
gem 'activemerchant', '1.7.1', :require => 'active_merchant'
It was also needed to go through each ERb and update block helpers. Rake task “rake rails:upgrade:check” can be used multiple times to check if you’re near the end.
I had a couple of “f.error_messages” warnings as well. It’s suggested to install “rails plugin install git://github.com/rails/dynamic_form.git” but I made a partial instead to have complete control over my displayed error messages.