1

我只是想在我的索引頁面中添加範圍,這樣我就可以過濾legal_cases哪個specific role包含在他們的角色關聯中,Role和LegalCase有多對多關聯 我試圖如何使用範圍過濾active_admin中的多對多

ActiveAdmin.register LegalCase do 
    scope :film_maker, joins(:roles).where('roles.name = ?', "Film Maker") 
end 

,但我得到這個錯誤

undefined method `joins' for #<ActiveAdmin::ResourceDSL:0x9ca28f4> 

任何幫助,請我應該用什麼來代替這裏的加入?

+0

你是怎麼解決這個問題了,我這樣做了類似的情況。我有一個類似的問題。請幫忙 – 2012-09-12 07:11:28

+0

@AmalKumarS我到目前爲止沒有找到解決方案,儘可能地提出並分享問題,如果您找到解決方案,請在此處添加。 – Azzurrio 2012-09-12 17:35:48

回答

0

我用一個這樣的

ActiveAdmin.register LegalCase do 

    controller do 
    def scoped_collection 
     end_of_association_chain.joins("left join users on users.id = bookings.user_id").select('bookings.*, users.*').order('users.name asc') 
    end 
    end 
end 
0

一個範圍添加到您所過濾模型,例如

class LegalCase < ActiveRecord::Base 

    ... 

    scope :film_makers, -> { joins(:roles).where(roles: { name: 'Film Maker' }) } 
end 
0

我在我的應用程序

ActiveAdmin.register Restaurant do 
    scope("All"){|scope| scope.order("created_at desc")} 

    Cuisine.all.each do |c| 
     scope(c.name) { |scope| scope.joins(:cuisines).where("cuisines.id=?",c.id)} 
    end 
end