views:

200

answers:

1

How do I add children to a parent using the awesome_nested_set plugin?

I have a model, Unit, which is a nested set. I'd like to add sub-units. Within the edit view, how I let the user add children (sub-units) to the parent (unit)?

+1  A: 

I have been implementing something with this gem recently and here's how I approached it:

In the _form partial I used a collection_select with

<%= f.collection_select :parent_id, Unit.root.self_and_descendants, :id, :name %>

where 'f' is supplied by your form_for and it assumes that Unit has a field 'name' to display in the Select but you can change that as needed.

Joc