且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

活动管理员对has_many列的计数进行排序

更新时间:2023-11-29 22:50:10

您可以添加 User 模型的 belongs_to:club上的计数器缓存列上的rubyonrails.org/association_basics.html#belongs-to-association-reference>计数器缓存列 ,然后按如下所示创建索引:

You could add a counter cache column on teh User model's belongs_to :club, and then make your index like so:

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