1
我正在寻找动态选择通过使用选择和祖先的宝石,我希望有人做过之前。动态选择祖先的宝石,并选择
我有2000年左右(类别,子类别和关键字)都在STI和树形结构。在我的表单中,我为类别|使用了三个选择输入子类别|关键字,但我得到了巨大的子类别列表,甚至更大的关键字列表。我想隐藏所有子类别,它们不是预选类别的子类;与关键字一样。
希望这是有道理的,我正在尝试做什么。我非常感谢任何想法。
这里我到目前为止,所有这些代码工作很好。
class Company < ActiveRecord::Base
has_and_belongs_to_many :categories, :join_table => "companies_categories"
has_and_belongs_to_many :subcategories, :join_table => "companies_subcategories"
has_and_belongs_to_many :keywords, :join_table => "companies_keywords"
end
class Category < ActiveRecord::Base
has_ancestry :cache_depth => true, :depth_cache_column => :ancestry_depth
has_many :subcategories, :class_name => "Category", :foreign_key => :subcategory_id
has_many :keywords, :class_name => "Category", :foreign_key => :keyword_id
belongs_to :category
has_and_belongs_to_many :companies, :join_table => "companies_categories"
has_and_belongs_to_many :companies, :join_table => "companies_subcategories", :association_foreign_key => "subcategory_id"
has_and_belongs_to_many :companies, :join_table => "companies_keywords", :association_foreign_key => "keyword_id"
end
这里是JavaScript的
jQuery(function($){
$(".chosen-input").chosen();
$(".schosen-input").chosen();
$(".kchosen-input").chosen();
});
这里是我的形式
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "New Company" do
f.input :name, :required => true
end
f.inputs "Categories" do
f.input :categories,
:input_html => { :class => "chosen-input", :multiple => true, :style => "width: 700px;"},
:collection => Category.where(:ancestry_depth => '2')
f.input :subcategories,
:input_html => { :class => "schosen-input", :multiple => true, :style => "width: 700px;"},
:collection => Category.where(:ancestry_depth => '3')
f.input :keywords,
:input_html => { :class => "schosen-input", :multiple => true, :style => "width: 700px;"},
:collection => Category.where(:ancestry_depth => [4, 5, 6])
end
我也有兴趣...也许这可以帮助你? http://staal.io/blog/2013/02/26/mastering-activeadmin/ – James