Note: Before upgrading your Rails app, always make sure to save your code on a version control system, such as Git.
To upgrade from Rails 4.2 to Rails 5.0, you must be using Ruby 2.2.2 or newer. After upgrading your Ruby version if required, go to your Gemfile and change the line:
gem 'rails', '4.2.X'
to:
gem 'rails', '~> 5.0.0'
and on the command line run:
$ bundle update
Now run the update task using the command:
$ rake rails:update
This will help you to update configuration files. You will be prompted to overwrite files and you have several options to input:
Typically, you should check the differences between the old and new files to make sure you aren’t getting any unwanted changes.
Rails 5.0 ActiveRecord models inherit from ApplicationRecord, rather than ActiveRecord::Base. ApplicationRecord is the superclass for all models, similar to how ApplicationController is the superclass for controllers. To account for this new way in which models are handled, you must create a file in your app/models/ folder called application_record.rb and then edit that file’s contents to be:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end