这是类别模型.类别可以属于另一个类别.
class Category < ActiveRecord::Base
attr_accessible :title, :parent_id
has_and_belongs_to_many :products, :join_table => :products_categories
belongs_to :parent, :foreign_key => "parent_id", :class_name => "Category"
has_many :categories, :foreign_key => "parent_id", :class_name => "Category"
end
Run Code Online (Sandbox Code Playgroud)
这是产品型号:
class Product < ActiveRecord::Base
attr_accessible :comment, location_id, :category_ids
has_and_belongs_to_many :categories, :join_table => :products_categories
belongs_to :location
end
Run Code Online (Sandbox Code Playgroud)
在产品的Active Admin表单中,我希望根据其parent_id对复选框进行分层排序,例如
以下是我的表格:
ActiveAdmin.register Product do
form do |f|
f.inputs "Product" do
f.input :comment
f.input :categories, :as => :check_boxes
f.input :location
end
f.buttons
end
end
Run Code Online (Sandbox Code Playgroud)
目前,表单会拉入复选框并正确保存数据,但我不知道从哪里开始对它们进行分组.我查看了文档,但看不到任何明显的东西.