Save 36% for Black Friday! Learn more

All threads / How to run rails initialization code that relies on all classes being loaded?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to run rails initialization code that relies on all classes being loaded?

Andrew Max asked in Rails

I have some crucial application setup code that I want to run once on application spinup that requires iterating through classes of a certain type and calling a gem specific initialize method on them.

According to https://stackoverflow.com/questions/56402093/how-can-i-preload-concerns-in-a-rails-initializer-using-rails-6-zeitwerk I should not autoload constants in initializers.

So how can I run code once on application load after classes are loaded

I tried with no luck:

    config.after_initialize do
      # do stuff
    end
Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.