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

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.