Save 36% for Black Friday! Learn more

Rails Lazy Load Hooks Cheatsheet

ActiveSupport in Rails provides hooks for when classes are lazily loaded. You can use this to add features to your Rails application when things are loaded.

Rails provides Lazy Load Hooks through ActiveSupport. We can listen for when something loads and execute a block when it runs with on_load.

Here's an example how to use it:

ActiveSupport.on_load(:active_record) do
  include Multitenancy
end

Available Lazy Load Hooks in Rails

For more details, check out the Rails Engines Guide - Available Load Hooks