2

我有 3 个相关模型:

class Brand < ActiveRecord::Base
  has_many :car_models
end

class CarModel < ActiveRecord::Base
  has_many :production_years
  belongs_to :brand
end

class ProductionYear < ActiveRecord::Base
  belongs_to :car_model
end

那么,如果我想按品牌进行过滤,我如何在 ActiveAdmin production_year 部分制作自定义过滤器?那里的默认过滤器:car_model 选择和年份值

4

1 回答 1

4

你尝试过这样的事情吗?

ActiveAdmin.register ProductionYear do
  filter :brand, :as => :check_boxes, :collection => proc { Brand.all }
end

编辑哎呀我没有注意到你的关联的复杂性,我认为如果你将它添加到你的 ProductionYear 类中,事情应该会更好:

class ProductionYear < ActiveRecord::Base
   belongs_to :car_model
   has_one :brand, :through => :car_model
end
于 2011-10-18T09:16:02.173 回答