Skip to content

Commit

Permalink
Use Zeitwerk for loading models in Rails 6
Browse files Browse the repository at this point in the history
In Rails 6, model loading is no longer working. This is because Zeitwerk has
replaced the original code loading. We now use Zeitwerk if it's available.
  • Loading branch information
mikeastock committed Nov 18, 2019
1 parent 6f283be commit e579538
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/algoliasearch/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module AlgoliaSearch
module Utilities
class << self
def get_model_classes
Rails.application.eager_load! if Rails.application # Ensure all models are loaded (not necessary in production when cache_classes is true).
if defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled?
Zeitwerk::Loader.eager_load_all
elsif Rails.application
Rails.application.eager_load!
end
AlgoliaSearch.instance_variable_get :@included_in
end

Expand Down

0 comments on commit e579538

Please sign in to comment.