googleads
Upgrading to Rails 5.0 from Rails 4.2 | Hire ROR Developers India,USA
preloder
Ruby on Rails Technical

Upgrading to Rails 5.0 from Rails 4.2

Why to Upgrade?

Rails 5.0 has a lot of new features. It addresses many issues and dealing with performance, security and new features like ActionCable, Rails API, Turbolinks 3 and etc. Check this out for more details: http://weblog.rubyonrails.org/2016/6/30/Rails-5-0-final/
Prerequisites
Rails 5.0 requires Ruby 2.2.2 or greater versions
Upgrade your application to Rails 4.2
Decent code coverage to make upgrade easier
Let’s do the steps for an upgrade, now:

1) Update ruby

Rails 5.0 requires ruby greater than 2.2.2. So install latest stable ruby version using RVM

2) Update your gem dependencies to rails 5

Change rails version in Gemfile

Update Rails dependencies

3) Update rails binaries and configurations

Run the following command for updating rails 5.0 configurations. This will add/modify the changes in bin/ and /config folders.

4) Generate DB schema rb file

Rails moved foreign and unique indexes to inside the create_table methods. To include these changes run migration again. No need to have a pending migration to generate a new schema.

5) Application classes

Rails 5.0 has new application classes that you should have and inherit from, the same way as ApplicationController or ApplicationHelper. Those are:
ApplicationRecord
ApplicationMailer
ApplicationJob

ApplicationRecord

All your models should inherit from ApplicationRecord

ApplicationMailer

All your mailers should inherit from ApplicationMailer. Previous rails versions don’t have layouts for mailers. Create mailer layout under layouts directory.

ApplicationJob

Change your jobs to inherit from your new ApplicationJob

6) Validation changes

Rails 5.0 has changed the belongs_to relation to require presence by default.

You have to create an initializer to explicitly configure the new behavior for the app

And for every belongs_to relation that is not required, just add optional: true.

7) Halt callback chain – throw(:abort)

Active Recor d or Active Model callbacks no longer halt when returning false. You should create initializer to explicitly configure this

Then you have to handle false manually like below example

Conclusion

After all the above changes are implemented, we can run our application in Rails 5.0. As mentioned, If you have a decent code coverage then the upgrade will not be a big problem. However, check whether all gems supporting, are up-to-date. To know more about Ruby on Rails web application development follow Agira Technologies.

The following two tabs change content below.

Saravana

An enthusiastic Tech Lead with 7 plus years of experience in Web development arena. Owns legitimate experience in Ruby, Ruby On Rails, AngularJs, DevOps. Golang, Another add on, This young tech freak never miss a chance to get his hands on planting and Gardening even in his busy weekends.

Leave a Reply

Your email address will not be published. Required fields are marked *

[contact-form-7 id="120788" title="Web Page Form"]

Schedule Your Call