21 Jul 2017

Ruby on Rails Upgradation from Version 3.x to 4.x in 5 Simple Steps

ruby, Ruby On Rails 0 Comment

This guide contains the general guidelines to follow for making the upgrade easier.


Before attempting to upgrade an existing application, you should be sure you have a good reason to upgrade.The best way to be sure that your application still works after upgrading is to have good test coverage before you start the process.

If you don’t have automated tests, you’ll need to spend time manually exercising all the parts that have changed. Do yourself a favour and make sure your test coverage is good before you start an upgrade.

Rails generally stays close to the latest released Ruby version when it’s released:

  • Rails 3 and above require Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially. You should upgrade as early as possible.
  • Rails 3.2.x is the last branch to support Ruby 1.8.7.
  • Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer.

The official Rails guide for upgrading from Rails 3.2 to 4.0 is very thorough. If your application is currently on any version of Rails older than 3.2.x, you should upgrade to Rails 3.2 before attempting one to Rails 4.0. However, if you’re using any non-standard gems, you’re mostly on your own. Some gems stopped being maintained before Rails 4 was released.

There is a gem “rails4_upgrade” which you can add to your Rails 3 project. It includes a Rake task that will help you with the upgrade. After adding the gem to your Gemfile run “bundle install”.

Step1. In your project root directory run the command “rake rails4:check”. Now instead of going through your currently bundled gems or Gemfile.lock manually, you get a report of what gems you need to upgrade.

Sample Output: 

Step2. Update the Gemfile with the newer version of Rails.

Step3. After resolving all the gem dependencies based on Step1 run “bundle install”. To find outdated gems there’s also “bundle outdated”, which you can run on any project.

Step4. Lastly, there’s the “rails:update” task, which you can use as a guideline as explained very clearly in this post to get rid of unnecessary code or monkey-patches, especially if your Rails 3 app was previously running on Rails 2

Step5. After everything done run the test cases and fix them as well.

Thank you for reading this article!