我有这些课程,以便在用户和顶部菜单上的所有记录中显示相关记录。
ActiveAdmin.register Position, :as => 'Positionsfake' do
belongs_to :user
controller do
def scoped_collection
end_of_association_chain.where(category: 1)
end
end
ActiveAdmin.register Position, :as => 'Contactsfake' do
belongs_to :user
controller do
def scoped_collection
end_of_association_chain.where(category: 0)
end
end
ActiveAdmin.register Position do
controller do
def scoped_collection
end_of_association_chain.where(category: 1)
end
end
ActiveAdmin.register Position, :as => 'Contacts' do
controller do
def scoped_collection
end_of_association_chain.where(category: 0)
end
end
ActiveAdmin.register User do
controller do
def scoped_collection
User.includes(:provider).where(:providers => {:user_id => nil})
end
end
index do
column :name
column "Positions" do |a|
link_to a.positions.count, admin_user_positions_path(a)
end
column "Contatcs" do |a|
a.contacts.count
end
actions
end
职位工作正常!但是联系人不能从这里打电话。
我只有一个型号。除类别字段外,联系人和职位相同。有什么方法可以解决这个问题吗?
感谢。
答案 0 :(得分:0)
这对我有用。
ActiveAdmin.register User do
controller do
def scoped_collection
User.includes(:provider).where(:providers => {:user_id => nil})
end
end
index do
column :name
column :positions do |a|
link_to a.positions.where(category: 1).count, admin_user_positions_path(a)
end
column 'Contacts', :positions do |a|
a.positions.where(category: 0).count
end
actions
end
ActiveAdmin.register User do
controller do
def scoped_collection
User.includes(:provider).where(:providers => {:user_id => nil})
end
end
index do
column :name
column 'Positions' do |a|
link_to a.positions.where(category: 1).count, admin_user_positions_path(a)
end
column 'Contacts', 'Positions' do |a|
a.positions.where(category: 0).count
end
actions
end