2017-05-10 246 views
0

所以,我有我想添加到項目中的類別和子類別,我嘗試使用awesome_nested_set gem,但無法找到放置實際類別名稱的位置。類別和子類別Rails

我不希望用戶能夠編輯,更新或刪除任何類別或子類別,我只希望他們作爲下拉菜單,以便他們可以選擇類別然後選擇子類別選擇添加到列表頁面。

我迄今爲止代碼:

這是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}" } %> 

所以,我的問題是,我在哪裏放置類別名稱,以及如何將它們鏈接到潛艇?

+0

你的問題是什麼? –

+0

編輯帖子的結尾 –

回答

0

沒關係。關閉這些東西的人可以繼續,現在就這樣做。我找到了一個解釋它的YouTube視頻。

這與問題並不過分相關,但視頻是MacKenzie Child 12個應用程序在12周的工作板視頻....我沒有鏈接,但它應該出現在YouTube搜索,如果你鍵入in。

我想通過觀看他爲他創建的各種類型的工作創建分類來回答我的答案。

再次感謝。