Basically, I have 4 levels of nested forms. A has B has C has D, with D being polymorphic (A also has D). I edit all of them on one form, with javascript to add/remove B, C, and D objects.
The problem is that whenever I edit D without editing any attributes from A, B, or C, the changes do NOT save. This includes adding D’s or editing attributes of existing D’s.
If I change an attribute in any of the parent models (A, B, or C), then the changes save.
I have the exact same problem as Marking multi-level nested forms as "dirty" in Rails
It was determined in that question that it was a bug in Rails 2.3.5. I’m running 2.3.11. Could it be possible that the bug was reintroduced? Does anyone know how to check?
Greatly appreciated… Thanks!
Steven, I believe that this is a real bug in Rails. I submitted a bug report on this at one point, but it never gained traction. I think the problem is non-trivial, and I don’t yet have time to dig into the Rails code and figure out the right fix.
My workaround was simply to be sure that somewhere along the line I “dirtied” the parent record. I believe that simply being sure that you set a value on the parent record will do the trick, even if that value is not different than the one in the db.
When I was working on this issue, I created a jQuery dynamic parent/child/grandchild form method. You can find it here if it might be of some use to you: http://amillionbetterthings.com/2010/06/24/rails-nested-forms-with-ajax-add-and-remove/.