【发布时间】:2017-10-08 15:27:04
【问题描述】:
所以,我有一些类别和子类别要添加到项目中,我尝试使用 awesome_nested_set gem,但找不到放置实际类别名称的位置。
我不希望用户能够编辑、更新或删除任何类别或子类别,我只希望它们作为下拉菜单,以便他们可以选择类别,然后选择子类别,然后进行选择添加到列表页面。
到目前为止我的代码:
这是在 category.rb 中
class Category < ApplicationRecord
has_many :subcategories
end
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.integer :parent_id, :null => true, :index => true
t.integer :lft, :null => false, :index => true
t.integer :rgt, :null => false, :index => true
# optional fields
t.integer :depth, :null => false, :default => 0
t.integer :children_count, :null => false, :default => 0
end
end
def self.down
drop_table :categories
end
end
class Category < ActiveRecord::Base
acts_as_nested_set
end
这是在 _form.html.erb 中的部分类别:
<%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
所以,我的问题是,我将类别名称放在哪里以及如何将它们链接到 subs?
【问题讨论】:
-
你有什么问题?
-
编辑文章结尾