2
我有以下型號ActiveAdmin:排序關聯計數
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