Topic: Multi-Model edit form with ajax and undo
In an edit-form for my Order model I want to be able to edit the order and assign new associations(order_items) to it. I do this using a small ajax form. After submitting the ajax-form to add stuff, the list of order_items nicely updates and the totals get updated too.
The problem arrives because I have save and cancel buttons on the screen.
Pressing cancel should also remove the added order_items, or re-add the ones that got deleted.
To be more precise: while on the edit-form, the changes should only get applied when the user clicks save, so adding and removing order_items should not instantly be applied.
The way I'm solving this right now is by keeping a clone of the model that's being edited in the session(I know this is very bad). I also keep an array of order_items in the session, because 'order << order_item' would otherwise instantly save the order_item. All in all it's becoming more and more hacky, so I want to change this behavior.
what would be (a|the) best way to solve this?