Rails 3, ActiveDmin Custom Filter
-
25-10-2019 - |
Frage
Ich habe 3 assoziierte Modelle:
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
Wie kann ich also im Abschnitt "ActiveADmin Production_year" einen benutzerdefinierten Filter machen, wenn ich die Filterung nach Marke machen möchte? Standardfilter dort: CAR_MODEL SELECT UND JAHRE VALUE
Lösung
Hast du so etwas versucht?
ActiveAdmin.register ProductionYear do
filter :brand, :as => :check_boxes, :collection => proc { Brand.all }
end
Bearbeiten Sie oops Ich habe die Komplexität Ihres Vereins nicht bemerkt. Wenn Sie dies zu Ihrer Produktionsstufe hinzufügen, sollten die Dinge besser funktionieren:
class ProductionYear < ActiveRecord::Base
belongs_to :car_model
has_one :brand, :through => :car_model
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow