Active admin sorts has_many column count

Using the Active Admin structure, I can add a “Users” column that summarizes the score for a specific “club” by doing this:

ActiveAdmin.register Club do
  index do
    column 'Users' do |club|
      club.users.count
    end
  end
end

Can I do this sorting somehow?

+4
source share
1 answer

You can add a cache column to Usermodel belongs_to :club, and then make your index as follows:

ActiveAdmin.register Club do
  index do
    column 'Users', sortable: :users_count do |club|
      club.users.count
    end
  end
end
+4
source

Source: https://habr.com/ru/post/1526663/


All Articles