All Articles

What happened to ActiveRecord::Base in Rails 5?

As the article title says What happened to ActiveRecord::Base?. This question came to me when I was creating a sample application in Rails 5 and noticed that the models no longer inherit from ActiveRecord::Base they inherit from ApplicationRecord.

# User model
class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable
end

When I googled a bit about it found that it is no different than ActiveRecord::Base. In Rails 5, a default application_record.rb file is created which in turn inherit from ActiveRecord::Base.

Previously if we wanted to add a functionality or override any ActiveRecord::Base method we had to monkey patch methods. But in Rails 5 we can simply add those methods to application_record.rb file.

(Read more about it here.)[https://blog.bigbinary.com/2015/12/28/application-record-in-rails-5.html]