繁体   English   中英

Rails 3,ActiveAdmin自定义过滤器

[英]Rails 3, ActiveAdmin custom filter

我有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 select和year值

你尝试过这样的事情吗?

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

EDIT oops,我没有注意到您的关联的复杂性,我认为如果将其添加到ProductionYear类中,则效果会更好:

class ProductionYear < ActiveRecord::Base
   belongs_to :car_model
   has_one :brand, :through => :car_model
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM