我使用的是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,那么我们需要做什么? –