我有以下型号
class User < ActiveRecord::Base
has_many :reviews
end
class Review < ActiveRecord::Base
belongs_to :user
end
我想按每个用户拥有的评论数量对我的 ActiveDdmin 页面上的用户进行排序。
我试过了,但没有运气:(来自this SO question)
ActiveAdmin.register User do
filter :name
index do
column :name
column :email
column "Facebook" do |u|
if u.provider == "facebook"
"Yes"
end
end
column "No. of reviews", :sortable => :"reviews.count" do |u|
u.reviews.count
end
end
controller do
def scoped_collection
end_of_association_chain.includes(:reviews)
end
end
end