سؤال

I have 3 associated models:

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? 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

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top