我正在尝试使用祖先 Ruby on Rails 3 制作类别树。我的 _form.html.erb
<%= form_for(@category) do |f| %>
<% if @category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% @category.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :ancestry %><br />
<%= f.collection_select :ancestry, Category.all(:order => "title"), :id, :title, :include_blank => true %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我的 index.html.erb:
<ul id="menu">
<% for category in @categories %>
<li><%= link_to h(category.title), category %>
<%= link_to "subcategory", new_category_path(:parent_id => category) %> |
<%= link_to "Destroy", category, :confirm => "Are you sure?", :method => :delete %>
<%= link_to 'Show', category %>
</li>
<% end %>
</ul>
我应该如何更改索引以显示所有类别树?我试图将索引更改为:
<ul id="menu">
<% for category in @categories %>
<li><%= category.subtree.all(:order => :title, :limit => 10) %>
<%= link_to "subcategory", new_category_path(:parent_id => category) %> |
<%= link_to "Destroy", category, :confirm => "Are you sure?", :method => :delete %>
<%= link_to 'Show', category %>
</li>
<% end %>
</ul>
但更改后看不到标题:#<Category:0xb5fb731c>#<Category:0xb5fb6fc0>