Search code examples
ruby-on-railsruby-on-rails-3ancestry

Display Ancestry name instead of id


My applications currently uses the Ancestry gem to create a navigation tree.

How do I display the name of a page which is the parent of another in the index view?

i.e. currently I do...

<% @pages.each do |page| %>
  <tr>
    <td><%= link_to page.name, edit_page_path(page) %></td>
    <td><%= page.ancestry %></td>
  </tr>
<% end %>

I want the page.ancestry to be the parent's name, not the ID.


Solution

  • <td><%= page.parent.name %></td>
    

    isn't it working?