# Acts\_as\_tree question

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-question/183158>\
**Category:** Rails\
**Created:** [February 9, 2010, 6:48am UTC](https://www.ruby-forum.com/t/acts-as-tree-question/183158 "2010-02-09T06:48:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![db\_333](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@db\_333](https://www.ruby-forum.com/u/db_333)\
**Post date:** [February 9, 2010, 6:48am UTC](https://www.ruby-forum.com/t/acts-as-tree-question/183158/1 "2010-02-09T06:48:48Z")

</div>

Hi,

I’m trying to implement a very simple acts\_as\_tree search in my index  
html.

I am able to show the parents, with no issue, but the children will  
not show.

I have something like this for the parent, which displays fine:

\<% for group in Group.roots %\>

+ \<%= link\_to (group.name), group %\>   

For the children, however, using the following will not work because  
it is looking to the index method.

\<% for group in Group.children %\>  
\<%= link\_to (group.name), groups %\>

Any pointers? Should I be using object.children to get the children?  
thanks

---

<div class="post-metadata">

**Author:** ![db\_333](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@db\_333](https://www.ruby-forum.com/u/db_333)\
**Post date:** [February 9, 2010, 8:49am UTC](https://www.ruby-forum.com/t/acts-as-tree-question/183158/2 "2010-02-09T08:49:22Z")

</div>

Yes, this was helpful, and I appreciate it. Thanks for your reply.

On Feb 8, 11:29 pm, Gianluca T.

---

<div class="post-metadata">

**Author:** ![db\_333](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@db\_333](https://www.ruby-forum.com/u/db_333)\
**Post date:** [February 9, 2010, 8:31am UTC](https://www.ruby-forum.com/t/acts-as-tree-question/183158/3 "2010-02-09T08:31:13Z")

</div>

Hi,

I think you’ve made a little mistake…

The correct form is this:

\<% for group in Group.roots %\>  
…  
\<%= link\_to (group.name), group %\>  
…  
\<% for child in group.children %\>  
…  
\<%= link\_to (child.name), child %\>  
…

Notice the use of “group.children” instead “Group.children”

Hope this helps…

---

<div class="post-metadata">

**Author:** ![db\_333](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@db\_333](https://www.ruby-forum.com/u/db_333)\
**Post date:** [February 9, 2010, 2:13pm UTC](https://www.ruby-forum.com/t/acts-as-tree-question/183158/4 "2010-02-09T14:13:03Z")

</div>

db\_333 wrote:

> Yes, this was helpful, and I appreciate it. Thanks for your reply.
> 
> On Feb 8, 11:29ï¿½pm, Gianluca T.

You probably don’t want acts\_as\_tree in any case. Awesome\_nested\_set is  
much more efficient.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
