Hi everybody,
I am using Rails 2.3 and the new “nested forms” concept to add child
objects to a parent object from within a single form.
I have successfully gotten the example app from Github (alloy_complex-
form-examples) to run and modified the Javascript code (add_child) to
insert new child elements betwee existing children, not only at the
end of the list of children. This works fine, client-side.
However, this order is not preserved. When I try to save the form, the
new children are simply appended to the list of children. Now I could
solve this by populating a “position” attribute using Javascript. But
when validation fails, the list of children is also reordered before
Rails re-renders the form, so that new children always appear at the
end.
How do I define, within a form_for / fields_for construct, the ORDER
of child elements so that it will be preserved
- upon re-rendering the form (when validations fail or exeptions
occur) - upon successfully saving the object
?
I have a “default_scope :order => :position” set in the child model,
which also works fine, but does not help in the first case.
How is the “accepts_nested_attributes_for” implemented, can I somehow
hook into this?
Thanks!
Jens