Rails 3,ActiveAdmin自定义过滤器 [英] Rails 3, ActiveAdmin custom filter
本文介绍了Rails 3,ActiveAdmin自定义过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有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 value
So, how i can make custom filter in ActiveAdmin production_year section, if i want make filtering by Brand? Default filters there: car_model select and year value
推荐答案
您尝试过类似的东西吗?
Did you try something like this?
ActiveAdmin.register ProductionYear do
filter :brand, :as => :check_boxes, :collection => proc { Brand.all }
end
编辑哎呀,我没有注意到您的协会,我认为如果将其添加到ProductionYear类中,则效果会更好:
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:
class ProductionYear < ActiveRecord::Base
belongs_to :car_model
has_one :brand, :through => :car_model
end
这篇关于Rails 3,ActiveAdmin自定义过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文