ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

3-level nested form incorrectly saves form attributes #281

Closed xqwztis closed 10 years ago

xqwztis commented 10 years ago

Hi

I'm trying to build a 3-level nested form (Ovary -> Formation -> Chamber), where Ovary is declared with a class_name to allow two ovaries be saved in the same table for each examination record.

However, when I try to create a sample record as shown on the screenshot

screenshot

The resulting view output is incorrect, because instead of creating a chamber under one formation, the application creates two formations, one is blank with the child chamber assigned to it, the other formation has no chamber but has correct data from the form.

html_source

Probably this is because of incorrect nesting of the parameters passed by the controller:

params

https://gist.github.com/xqwztis/6163228

A sample application that has the problem can be found here: https://github.com/xqwztis/nested_form_issue.

Any ideas why this could be happening?

xqwztis commented 10 years ago

The problem was due to Chamber attributes in the form being enclosed in <div> with class "fields", which lead to blank context variable in javascript, which in turn resulted in the newly generated chamber instance not attributed to its parent.