I know that you accepted the answer, but I did it before , and therefore it would be useful to explain how we did it:
-, . acts_as_tree
- acts_as_tree
, ancestry
, , - ancestry
(parent
, child
..).
ancestry
- , acts_as_tree
:
class Category < ActiveRecord::Base
has_ancestry
end
ancestry
( parent_id
) categories
( ) child
, :
@category.parent
@category.children
... ..
-
, child
( ).
. ancestry
/acts_as_tree
- .
parent
"" :
![enter image description here](https://fooobar.com/undefined)
ancetry
. , acts_as_tree
, ( ), :
class CategoriesController < ApplicationController
def index
@categories = Category.all
end
end
<%= render @categories %>
<%= category.name %>
<%= render category.children if category.has_children? %>
:
![enter image description here](https://fooobar.com/undefined)
:
@subcategories = Category.where parent_id: @category.id
, :
resources :categories
class CategoriesController < ApplicationController
def show
@category = Category.find params[:id]
end
end
:
<% @category.children.each do |subcategory| %>
<%= subcategory.name %>
<% end %>
![enter image description here](https://fooobar.com/undefined)