# Creating Dynamic Tree Menu in Rails

**URL:** <https://www.ruby-forum.com/t/creating-dynamic-tree-menu-in-rails/126424>\
**Category:** Rails\
**Created:** [January 18, 2008, 5:11am UTC](https://www.ruby-forum.com/t/creating-dynamic-tree-menu-in-rails/126424 "2008-01-18T05:11:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zscott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/9fc348/32.png) [@zscott](https://www.ruby-forum.com/u/zscott)\
**Post date:** [January 18, 2008, 5:11am UTC](https://www.ruby-forum.com/t/creating-dynamic-tree-menu-in-rails/126424/1 "2008-01-18T05:11:23Z")

</div>

Hello all,  
I need a good technique to create a tree menu based off pages in a  
database with RoR. So, pages would look something like this in the db:

pages (  
id  
parent\_id  
title  
content  
)

Obviously, the parent\_id would be 0 or null for the top-level pages  
and any sub-pages would have the id under parent\_id. What I’m looking  
for as far as a read-out is a simple unordered-list with sub-lists  
under the parent’s list item… so:

- Parent 
  - Child 1
  - Child 2

If I can have it be recursive that would also be great.

Thanks

---

<div class="post-metadata">

**Author:** ![zscott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/9fc348/32.png) [@zscott](https://www.ruby-forum.com/u/zscott)\
**Post date:** [January 18, 2008, 5:32am UTC](https://www.ruby-forum.com/t/creating-dynamic-tree-menu-in-rails/126424/2 "2008-01-18T05:32:26Z")

</div>

Have a look into acts\_as\_tree.

On Jan 18, 2008 2:40 PM, zscott [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> )
> 
> - Child 2
>   
> 
> If I can have it be recursive that would also be great.
> 
> Thanks
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![zscott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/9fc348/32.png) [@zscott](https://www.ruby-forum.com/u/zscott)\
**Post date:** [January 18, 2008, 7:56am UTC](https://www.ruby-forum.com/t/creating-dynamic-tree-menu-in-rails/126424/3 "2008-01-18T07:56:27Z")

</div>

Have a look here [http://www.vaporbase.com/postings/A\_Micro-CMS\_in\_Rails](http://www.vaporbase.com/postings/A_Micro-CMS_in_Rails)

linoj
