Forum: Ruby on Rails acts_as_tree and drop downs

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Will G. (Guest)
on 2007-06-24 23:25
(Received via mailing list)
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.
shai (Guest)
on 2007-06-25 11:26
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.
R. Elliott M. (Guest)
on 2007-06-25 13:03
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
Carl J. (Guest)
on 2007-06-25 19:40
> 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.
This topic is locked and can not be replied to.