开发者

Master-Detail on RoR with Ajax

What is the best pattern to do a master-detail form in Ajax using RoR? My form has an order and for each order there is a lot of itens. I want to do only one form where the user can set the order details and include, exclude and update itens. When the user insert an item, I am doing an AJAX call to my controller so the user can search for an product. But when this item is "saved" temporarly, I can't still save to my controller, because probably is not a good pattern to fill my controller w开发者_StackOverflow社区ith this data, as the user may gave up of the order inclusion. So I am saving on the client side on a JSON object. When the user is ready and saved the order, I am sending the fields of the order together with the JSON object of the itens. The problem I see, is that I need a lot of code on the client side, and messing with JS is not easy stuff... Any better suggestions?


Use your Ajax call to create a hidden input for each order item, e.g. order[item_ids][].

Then, let your order model accept these using an item_ids= method, which would create the associations when the order is saved.


Store a session variable for new_order_item_ids which you would append to in your controller, as you save each order item via their Ajax call.

Then, read this back when saving your order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜