Skip to content

Instantly share code, notes, and snippets.

@wstrinz
Last active December 14, 2015 15:37
Show Gist options
  • Save wstrinz/3a786bf7c47521f4ee50 to your computer and use it in GitHub Desktop.
Save wstrinz/3a786bf7c47521f4ee50 to your computer and use it in GitHub Desktop.
get count of all models in rails
Rails.application.eager_load!
getCounts = ->(model) { {model.to_s => model.try(:count) || "cant count" } }
ActiveRecord::Base.descendants.map(&getCounts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment