# Acts\_as\_tree and drop downs

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-and-drop-downs/107655>\
**Category:** Rails\
**Created:** [June 24, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/acts-as-tree-and-drop-downs/107655 "2007-06-24T21:25:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [June 24, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/acts-as-tree-and-drop-downs/107655/1 "2007-06-24T21:25:48Z")

</div>

Hello all,  
I’ve got an object called store\_section in which I have called the  
acts\_as\_tree function. In several of the views in my site, I have  
objects which need to specify the store\_section that they are in. What I  
would like is a way to allow the user to select the items out of a drop  
down list that shows them in the proper hierarchy with indentation to  
make it easier to select the right item. Is there a quick-and-dirty  
prebuilt Ruby solution to this, or do I need to create my own?

Thanks,  
Will

* * *

The fish are biting.  
Get more visitors on your site using Yahoo! Search Marketing.

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [June 25, 2007, 9:26am UTC](https://www.ruby-forum.com/t/acts-as-tree-and-drop-downs/107655/2 "2007-06-25T09:26:59Z")

</div>

you could probably create this on your own, but you should look into  
changing the acts\_as\_tree you’ve got there to an acts\_as\_nested\_set ;  
you’ll be saving a lot of queries to the db this way, if you want to  
display a whole tree… in one query, you can get a whole tree, branch,  
etc, without recursive calls to the db.

my recommendation anyways. maybe worth looking into.

Will G. wrote:

> Hello all,  
> I’ve got an object called store\_section in which I have called the  
> acts\_as\_tree function. In several of the views in my site, I have  
> objects which need to specify the store\_section that they are in. What I  
> would like is a way to allow the user to select the items out of a drop  
> down list that shows them in the proper hierarchy with indentation to  
> make it easier to select the right item. Is there a quick-and-dirty  
> prebuilt Ruby solution to this, or do I need to create my own?
> 
> Thanks,  
> Will
> 
> * * *
> 
> The fish are biting.  
> Get more visitors on your site using Yahoo! Search Marketing.

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [June 25, 2007, 11:03am UTC](https://www.ruby-forum.com/t/acts-as-tree-and-drop-downs/107655/3 "2007-06-25T11:03:37Z")

</div>

Not to counteract what shai said, but it’s not 100% necessary to use  
acts\_as\_nested\_set if, before rendering anything, you grab the entire  
tree somehow. If all the objects of the tree share something specific  
in common, such as root\_id, then nested set might not be necessary.

I’ve always been wary of nested set; it saves queries in some places but  
creates more elsewhere; IMO maintenance of a nested set is actually a  
nightmare behind the scenes.

If you decide to use nested set, I would suggest better\_nested\_set.

[http://agilewebdevelopment.com/plugins/betternestedset](http://agilewebdevelopment.com/plugins/betternestedset)

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [June 25, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/acts-as-tree-and-drop-downs/107655/4 "2007-06-25T17:40:40Z")

</div>

> If you decide to use nested set, I would suggest better\_nested\_set.
> 
> [http://agilewebdevelopment.com/plugins/betternestedset](http://agilewebdevelopment.com/plugins/betternestedset)

I completely agree – betternestedset is fantastic. You will need to add  
some columns to your table though (to indicate left and right position).  
However it has the hierarchy drop down function you want.
