rails can call a model in the initializer file

As long as your migrations were already executed and the table for the model in question already exists, I believe you will be able to call your model from the initializer file as usual: Model.method().

If you want to check if the table exists, you could do like this:

if ActiveRecord::Base.connection.table_exists? :settings

Finally, if you want to make sure all other initializers have run before running this one, you could add the following code to your initializer:

# config/initializers/rack_attack.rb
Rails.configuration.after_initialize do

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top