2012-05-07 31 views
3

我試圖簡單地允許篩選ActiveAdmin的位置頁面上的類別。通過Active Admin設置has_many通過篩選器

我有三個型號:

class Location < ActiveRecord::Base 
    has_many :categories_locations 
    has_many :categories, :through => :categories_locations 

class CategoriesLocation < ActiveRecord::Base 
    belongs_to :category 
    belongs_to :location 
end 

class Category < ActiveRecord::Base 
    has_many :categories_locations 
    has_many :locations, :through => :categories_locations 
end 

在我的地點頁面中,我使用這個過濾器:

ActiveAdmin.register Location do 
    filter :name 
    filter :category, :collection => proc { Category.all }, :as => :select 

然而,不斷拋出的錯誤。

undefined method `category_eq' for #<MetaSearch::Searches::Location:0x007fd4f9b965d8> 

我試過filter:categories,filter:categories_locations,但什麼都不會有效。

有沒有人經歷過這種 - 任何人都有解決方案?

+0

上午有同樣的問題,我無法從移動HABTM通過對HAS_MANY /,所以任何真正的解決這個? –

回答

1

在某一點的has_many /通過比的habtm更靈活(你可以有附加字段等等)

+0

這是如何被選爲接受的答案? – wkhatch

0

爲什麼不使用habtm?

class Location < ActiveRecord::Base 
    has_and_belongs_to_many :categories 

class CategoriesLocation < ActiveRecord::Base 
end 

class Category < ActiveRecord::Base 
    has_and_belongs_to_many :locations 
end 

然後

ActiveAdmin.register Location do 
    filter :name 
    filter :category_id, :collection => proc { Category.all }, :as => :select