# Which acts\_as to use?

**URL:** <https://www.ruby-forum.com/t/which-acts-as-to-use/77895>\
**Category:** Rails\
**Created:** [December 1, 2006, 11:24am UTC](https://www.ruby-forum.com/t/which-acts-as-to-use/77895 "2006-12-01T11:24:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [December 1, 2006, 11:24am UTC](https://www.ruby-forum.com/t/which-acts-as-to-use/77895/1 "2006-12-01T11:24:37Z")

</div>

I’m planning a custom CMS for a job. The idea is that I want would like  
the user to build up the site using pages (these are model objects).  
These pages would be like a tree structure: one homepage then three sub  
pages each subpage has more subpages etc.

Now can someone recommend which of these to use and why?:

acts\_as \_threaded  
acts\_as\_list  
acts\_as\_nested

I don’t want to try and use each one to find out which is most suited to  
my problem. It would be similar in concept to Radient but due to the  
custom nature of the job i’m building from scratch.

Any comments or code samples welcome. I’m not new to Rails but i’m no  
way an expert!

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [December 1, 2006, 11:35am UTC](https://www.ruby-forum.com/t/which-acts-as-to-use/77895/2 "2006-12-01T11:35:22Z")

</div>

On 12/1/06, James W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> acts\_as\_list  
> You said that it’s a tree strcuture, so don’t use acts\_as\_list at all.

acts\_as\_nested

You can use acts\_as\_threaded, acts\_as\_tree or acts\_as\_nested set. I  
recommend you the later. It’s better for retrieving the tree from the  
database. It can do it with only one query.

Regards,  
Rodrigo.

I don’t want to try and use each one to find out which is most suited to

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [December 1, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/which-acts-as-to-use/77895/3 "2006-12-01T14:17:36Z")

</div>

Rodrigo A. wrote:

> On 12/1/06, James W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > acts\_as\_list  
> > You said that it’s a tree strcuture, so don’t use acts\_as\_list at all.
> 
> acts\_as\_nested
> 
> You can use acts\_as\_threaded, acts\_as\_tree or acts\_as\_nested set. I  
> recommend you the later. It’s better for retrieving the tree from the  
> database. It can do it with only one query.
> 
> Regards,  
> Rodrigo.
> 
> I don’t want to try and use each one to find out which is most suited to

Thanks, what is the difference between them all I can’t seem to find a  
relevant answer. The structure will be in a tree for navigation purposes  
and because I would like to `cascade` certain properties down the tree  
from the parent.

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [December 1, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/which-acts-as-to-use/77895/4 "2006-12-01T14:45:58Z")

</div>

On 12/1/06, James W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > You can use acts\_as\_threaded, acts\_as\_tree or acts\_as\_nested set. I  
> > relevant answer. The structure will be in a tree for navigation purposes  
> > and because I would like to `cascade` certain properties down the tree  
> > from the parent.

The tree aproach uses a parent\_id in children nodes, pointing to their  
parents. This means that if you have several levels, you will need more  
than  
one query to retrieve the tree from the database.

The nested set approach is more complex, but once understood, it makes a  
lot  
of sense. The insert and delete actions are more expensive than in the  
normal tree approach, but you can read a whole tree, or may a branch  
with  
only one query. You could know how many children a node has too.

You can read more about nested sets here  
[http://www.edutech.ch/contribution/nstrees/index.php](http://www.edutech.ch/contribution/nstrees/index.php)  
You can google for more explanations too.

Regards,  
Rodrigo.

–
