Tuesday 4 June 2013

Upgrading to Rails 3



This blog is simply just a narrative of my progress upgrading a large rails 2.3.18 project to rails 3. Hopefully it might make someone's life a bit easier.

Specs From: Rails 2.3.18, Ruby 1.8.7 and Ubuntu 12.04
Specs To: Rails 3.0.6, Ruby 1.8.7 and Ubuntu 12.04


I started on a new branch working my way through the omgbloglol guide to upgrading rails 2 to 3. Rather than installing rails through git clone, I included it in the gemfile as the current head state is into the Rails 4


Include:

gem “rails”, “<=3.0.6”

in the Gemfile and run bundle install to install rails.


The first problem was factory_girl latest gem requires ruby 1.9.2. I was hoping to keep working in baby steps by using ruby1.8.7 until rails 3.0.X is up, running and tested so I've specified version 2.6.5 in the Gemfile which is the last version to work for ruby 1.8.7.
gem “factory_girl”, “<=2.6.5”


Next issue was courtesy of rdoc, or so I thought

$ rails --version
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
/home/niall/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.4/lib/rake/rdoctask.rb:1
/home/niall/.rvm/gems/ruby-1.8.7-p371/gems/rails-0.9.5/Rakefile:3:in `require'
/home/niall/.rvm/gems/ruby-1.8.7-p371/gems/rails-0.9.5/Rakefile:3

Checking the Rakefile, everything seemed okay - though as it happens, we have many baked-in plugins that have their own Rakefiles which has the obsolete require style included. Once this was replaced I got the same error. Reading the error a little more carefully I noted it says rails-0.9.5
I was asking for any rails  less than 3.X, so when another gem ‘validates_url_format_of’ required activerecord version have 2.3.4, Bundler used the desired activerecord and found a version of rails to fit in with that which happens to be as old as mankind. Specifying which rails version to use confirms this:

$ bundle update
Bundler could not find compatible versions for gem "activerecord":
 In Gemfile:
   validates_url_format_of (>= 0) ruby depends on
     activerecord (~> 2.3.4) ruby

   rails (= 3.0.6) ruby depends on
     activerecord (3.0.6)

If you've been getting this error it's probable the gem is incompatible. You'll need to find an alternative or lower your rails version to match. I commented out the gem validates_url_format_of and used an alternative.

After running rails new to get the new files necessary for a rails 3 app, I felt it was a good time to keep git up to speed. Running 

$ git status 

shows absolutely boat loads of script files have been modified. git diff says old mode <number> new mode <number>. These mean files have changed permission, in this case from when rails new was ran.

If you wish to ignore these on git, run:
$ git config core.filemode falsecour
Commit any new files that running rails new have created/modified.

subclasses_of is now deprecated is another error encountered along our path.
One of the plugins kept in the vendor folder has a line containing something to the extent of: 

Object.subclasses_of(SomeClass).each

which has now been deprecated. The appropriate translation for this is: 

SomeClass.descendants.each

The final issue we faced was this error message:

`deprecation_caller_message': stack level too deep (SystemStackError) with a total of  4763 levels in the error stack.

This error is due to recursion in the stack trace. Ours was because we used a logger called better_logging which used the deprecated constant RAILS_ROOT rather than the new method Rails.env. In order to deliver the error message, the error handler would call better_logging which would crash, which would trigger the error handler to call better_logging which carries on until the error stack overflow-eth. 
Sorry to be of little help but we simply switched to using an up-to-speed gem rather than the plugin when this happened.


No comments:

Post a Comment