Pierre Olivier Martel
Pierre Olivier Martel

Reputation: 3194

Hide records count from ActiveAdmin scopes

Active Admin lets you define scopes this way :

scope :all
scope :opened
scope :closed

The problem is that it will also display the total record count next to each scope on the index page. This COUNT query can slow down page load a lot when millions of records are involved. ActiveAdmin already lets you hide the total count for the index page this way :

index :pagination_total => false

Is there something similar for scopes? If so, I can't find it!

Upvotes: 13

Views: 3209

Answers (1)

Jonathan Allard
Jonathan Allard

Reputation: 19249

In v0.4.2, a commit was introduced adding a show_count option to scope:
[c12dc45] Adds ability to suppress scope count on a per-scope basis.

The included test (yay testing!) describes this well:

ActiveAdmin.register Post do
  scope :all, default: true, show_count: false
end

I'm not sure how the feature is documented; you might want to propose changes in that regard.

Upvotes: 21

Related Questions