Nested Forms and ordering of new child elements

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

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
* 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?