Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three level nested forms in rails using accepts_nested_attributes_for

I've been trying to implement a dynamic multi-model form with accepts_nested_attributes_for in my rails application. I've been following Eloy Duran's complex-forms example that shows a 2 level implementation, but I've been trying to expand this to 3 levels. Is there support with accepts_nested_attributes_for for a 3 level form? Can anyone show me how to expand the example app?

I've got the javascript partially working (doesn't always work for some reason) for the 3rd level, but I can't save the 3rd level object(s). The param name it is passing for each attribute is:

 greatgrandparent[grandparent_attributes][0][parent_attributes][0][object_attributes][1249277008434][attribute] 

Where greatgrandparent is the object the form is for, grandparent is the first level, parent is the second level, and object is the 3rd level (the one I'm trying to save).

Thanks, I appreciate any pointers.

like image 386
Anon Avatar asked Aug 03 '09 05:08

Anon


1 Answers

I have updated my complex-form-examples to work with Rails 2.3. See the deep branch for an example on deeply nested models.

git clone git://github.com/ryanb/complex-form-examples.git
cd complex-form-examples
git checkout -b deep origin/deep
rake db:migrate
script/server

It is the cleanest solution I've seen so far. If you find any bugs or improvements please add an issue on GitHub.

like image 134
ryanb Avatar answered Sep 23 '22 16:09

ryanb