Skip to content

Instantly share code, notes, and snippets.

View guillaumedev's full-sized avatar

GuillaumeDev guillaumedev

View GitHub Profile
@joost
joost / update_cache_counters.rake
Last active September 25, 2018 15:05 — forked from svyatov/update_cache_counters.rake
Rails Rake Task: Update all cache counters / counter caches.
# More robust version to update new or existing counter cache columns in your Rails app.
# See: https://gist.github.com/svyatov/4225663
desc 'Update all cache counters'
task :update_cache_counters => :environment do
models_to_update = {}
# or: Rails.application.eager_load!
# Dir loads less, so it's faster
Dir.glob(Rails.root.join('app/models/**/*')).each { |model| require model if File.file?(model) }