ruby-on-railsrubyactiveadminmeta-search

Setting up a has_many through filter with Active Admin


I'm trying to simply allow filtering of categories on the Locations page for ActiveAdmin.

I have three models:

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

On my locations page, I'm using this filter:

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

However, it keeps throwing an error.

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

I've tried filter :categories, filter :categories_locations, but nothing will work.

Has anyone experienced this –– anyone have a solution?


Solution

  • at some point has_many/through is more flexible than habtm (you can have additional fields etc)