Forum: Ruby on Rails acts_as_tree - how do I let the user create subnodes?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
92219cfdc7be3f0b854b05f76f3d34e3?d=identicon&s=25 alex (Guest)
on 2007-04-10 03:04
(Received via mailing list)

Noob here, so apologies in advance for my certain misunderstandings.

I have hierarchal category structure which I've modeled using
acts_as_trees.  I have successfully created the code to display the
categories in a tree-ish fashion (it was very easy - I'm impressed).
I would like to let users add new subcategories to an existing
category by clicking on a "new subcategory" link next to each category
name in this tree.  I am having problems doing this.

My approach has been:

In the href of the "new subcategory" html, I stick the id of the
parent like this:
  <a href="/categories/new?parent_id=1">

I can pick up the parent_id in the new action controller easily
    @category =
    @category.parent = Category.find(params[:parent_id])

But I loose it when I get to the create action controller, as the form
does not have the parent_id (nor do I want it to).

The I guess my basic issue is that I set up the parent that I want to
use in the list rendering, but I can't pass it all the way through to
the create action.

Any suggestions?

D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-04-10 11:58
(Received via mailing list)
the common method for cases like this is to save the parent_id in a
hidden field in the form.
Or save it in the session.
Or put it as a parameter in URL that the the form is calling.
92219cfdc7be3f0b854b05f76f3d34e3?d=identicon&s=25 alex (Guest)
on 2007-04-11 03:52
(Received via mailing list)
Ok, thanks.  I'll give the hidden field method a try.
This topic is locked and can not be replied to.