我使用的是Active Admin 0.3.2,而我的數據庫模式包含一些has_and_belongs_to_many關係。我可以創建並顯示記錄,但是試圖將它們包含在篩選器部分中會導致事情停止。如何在Active Admin過濾器部分使用HABTM字段?
型號\ pin.rb:
class Pin < ActiveRecord::Base
has_and_belongs_to_many :pin_types, :join_table => :pin_types_pins
end
型號\ pin_type.rb
class PinType < ActiveRecord::Base
has_and_belongs_to_many :pins, :join_table => :pin_types_pins
end
管理\ pins.rb
ActiveAdmin.register Pin do
filter :pin_types
...other filters
end
結果是其他過濾器的出現,但針類型沒有任何部分。
如果管理員\ pins.rb是這個:
ActiveAdmin.register Pin do
filter :pin_types, :as => :check_boxes
...other filters
end
我得到如下:
undefined method `pin_type_ids_in' for #<MetaSearch::Searches::Pin:0xcd2c108>
我希望做的是讓用戶選擇一個或多個引腳根據是否應用任何選定選項,從一組可能的選項和過濾器中篩選類型。
這可能嗎?
我自己找到了解決方案,[在GitHub上](https://github.com/gregbell/active_admin/issues/515)。 供參考:'filter:pin_types_id,:as =>:check_boxes,:collection => proc {PinType.all}' – ccarlson
如果我們想從pin創建Pintype,那麼我們需要做什麼? –