2

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

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

4 Comments

Yes, this cause error "Undefined methon 'brand_eq'" for #<MetaSearch::Searches::ProductionYear:...>
Ahhh the problem is in the model associations, I appended my answer to reflect this
Thanks a lot, now it really works! But maybe you can help next to. If i add one more child model for ProductionYear, how to make double 'through' association?
Got dropdown with values but when i filter with this , iam getting empty list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.