Acts_as_tree and drop downs


#1

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.


#2

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.


#3

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


#4

If you decide to use nested set, I would suggest better_nested_set.

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.