Created
March 4, 2022 17:55
-
-
Save rbrooks/f80011e2a60d0db03fc6b6e1b25ca770 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sometimes you need to reindex all Rails Models. The reindex() method | |
# is specific to the SearchKick gem for ElasticSearch, and it only exists | |
# on ElasticSearch-indexed tables. We do a check for its existence below, | |
# or it would throw an error. | |
Dir[Rails.root.join('app/models/*.rb').to_s].each do |filename| | |
klass = File.basename(filename, '.rb').camelize.constantize | |
next unless klass.ancestors.include?(ActiveRecord::Base) | |
next if klass.abstract_class? | |
klass.reindex if klass.respond_to?(:reindex) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment