How come your model class can call ::devise?

tomurb profile image Tomek Urban ・1 min read

I've decided to read some devise code, for learning purposes. Since I'm on that mission, I'll also write some posts. The thing the internet needs is another blog that will not be read.

Ok, let's get back to the question from the title.

When you'll install devise in your project it will add to your User class these four lines:

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

Nothing else changes in the class. So where the ::devise method comes from?

ActiveSupport.on_load(:active_record) do
  extend Devise::Models

What does ::on_load do? According to the documentation it:

Declares a block that will be executed when a Rails component is fully loaded.

That's all folks.

Posted on May 25 by:


markdown guide