Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading from Rails 2.3 to Rails 4.0

We have an application which is currently on Rails version 2.3.12 and Ruby version 1.8.7. We want to update our application to Rails 4.0 and Ruby 2.1.0. We have around 200 models and 150 controllers.

I would like to know how big an effort is it to undergo the upgrade process. Also can you provide steps which can be followed for the upgrade. Should we first upgrade Ruby and then Rails or vice-versa?

like image 900
DanMatlin Avatar asked Jan 10 '14 12:01

DanMatlin


2 Answers

What you want to achieve is gonna be an epic effort. I can't provide you the step by step instructions because it's impossible to cover all the cases in a single answer.

I recommend to not upgrade Ruby and Rails in parallels, but in small steps.

The complexity of the upgrade itself is huge, but it's not impossible as long as you have a reasonable test coverage of you application. I really hope you have tests. If you don't, then you can't even think to start an upgrade like this and you first need to ensure a minimum coverage for the product.

My suggestion is to follow this roadmap

  1. Upgrade Ruby from 1.8.7 to 1.9.3. Rails 2.3 is supposed to be compatible with Ruby 1.9 and you'll get the benefit of a more recent Ruby version. In fact, several gems have dropped support for Ruby 1.8.
  2. Leave the app settle and run for a while, just to make sure you can find and fix incompatibilities. Every time you find an issue, reproduce it with a test, then fix it.
  3. Upgrade Rails from 2.3 to 3.0.
  4. Same as point 2.
  5. Upgrade Rails from 3.0 to the latest 3.x version.
  6. Same as point 2.
  7. Upgrade Ruby from 1.9.3 to 2.0. The upgrade should be trivial.
  8. Same as point 2.
  9. Upgrade Rails from 3.x to the latest version

A few notes

  • The reason I suggested you to not upgrade from Rails 2.3 directly to 4, it's because it's almost impossible.
  • The reason I suggested you to not upgrade form Rails 2.3 directly to the latest 3.x, it's because from 3.0 to 3.x there is the asset pipeline new feature that is gonna cause you several headaches. It's better to handle this step separately and not in a big upgrade.
like image 134
Simone Carletti Avatar answered Nov 15 '22 04:11

Simone Carletti


Ruby 1.9 handles encoding differently than Ruby 1.8. Rails 2.3 is not well prepared for this. The issues often lead to hard errors, and may occur at unexpected places (like when you want to show a error message)

A good (or scary) overview is on this blog entry: http://www.rvdh.de/2010/01/06/why-you-cant-run-rails-23-apps-on-ruby-19/

I also lost a lot of time trying to bring Rails 2.3.x to work with Ruby 1.9.x (Maybe it is possible if you are always use plain ascii)

So you need first update to Rails 3.0 and then to Ruby 1.9.3 (or both at the same time)

The asset pipeline is nice when it works, but upgrading is difficult enough. So I would just disable it until you are on Rails 4.0.

There is a lot changed with the views, like form_for helper. It is good when you have tests that render each view at least once. You then will get deprecation warning for things that have changed. If this is not realistic, then you should try to test all things of your app manually, and grep the log files for the deprecation warnings. Many deprecations in Rails 3.0 will lead to errors or wrong behaviour in Rails 3.1.

like image 39
Meier Avatar answered Nov 15 '22 03:11

Meier