[英]Rails 3, ActiveAdmin custom filter
I have 3 associated models: 我有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
So, how i can make custom filter in ActiveAdmin production_year section, if i want make filtering by Brand? 因此,如果我想按品牌进行过滤,如何在ActiveAdmin production_year部分中进行自定义过滤器? Default filters there: car_model select and year value
那里的默认过滤器:car_model select和year值
Did you try something like this? 你尝试过这样的事情吗?
ActiveAdmin.register ProductionYear do
filter :brand, :as => :check_boxes, :collection => proc { Brand.all }
end
EDIT oops I didn't notice the complexity of your association, I think if you add this to your ProductionYear class things should work better: 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.