I''ve been doing a lot of work with pop up windows and have now come to the "it all works, but this" point in my application. I have an order application. With that I have a pop up window that allows users to do some dragging and dropping of items for a portion of the order. The problem is that the pop up uses the order id. The items selected in the pop up window are saved back to the order record as a user drags and drops items. Obviously works great with existing orders, but blows up with new orders. I am saving everything back to the order record. There is not a separate table to hold the list for this item of the order. Right now the I open the pop-up window using link_to and sending in the id of the order. If it''s a new order, I get "Couldn''t find Order without an ID". Since the Order ID is integral to everything working, what are my options? Do I check for the order ID and if it''s not provided, start a new order and save it to the database? Or do I add a route for the model/pop_up? Right now my route is map.resources :model, :collection => ["pop_up"] Or is this a bigger, uglier problem that really can''t be attacked with this design? If that''s the case, some ideas for how to fix, without starting all over would be appreciated. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hassan Schroeder
2008-May-05 13:30 UTC
Re: How can I save values before the record is created?
On Mon, May 5, 2008 at 5:54 AM, Becca Girl <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Right now the I open the pop-up window using link_to and sending in the > id of the order. If it''s a new order, I get "Couldn''t find Order > without an ID". > > Since the Order ID is integral to everything working, what are my > options? Do I check for the order ID and if it''s not provided, start a > new order and save it to the database?That sounds like it would work. Alternatively, create a new order when the page that launches the popup is called (or somewhere earlier in the process, like when an item is first added to the cart). HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Right now the I open the pop-up window using link_to and sending in the > id of the order. If it''s a new order, I get "Couldn''t find Order > without an ID". > > Since the Order ID is integral to everything working, what are my > options? Do I check for the order ID and if it''s not provided, start a > new order and save it to the database?That''s an option. Or I''d just create it arbitrarily before the pop up. Save grief :) Having a few extras around isn''t a problem. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roger Pack wrote: Or I''d just create it arbitrarily before the pop> up. Save grief :)As always, thanks for the great ideas. The pop-up is opened with link_to. When would the order be created? I don''t think that I really want to create the order when the new order window is opened, so I think that I''d want to create it after that. My thought is to put this in the controller that associated with the pop-up window opening and it''s params. Also, I know this is super basic, but could someone point me to some syntax that would create the new order and then grab the ID after the new order is saved in the db. Order.create just creates a nil value for ID. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
From an outsider''s perspective it sounds like you have two different but similar things going on: - Order#edit with drag-and-drop to add and remove items from an existing order - Order#new with drag-and-drop to set the initial list of items on the order The fact that these two distinct actions have very, very similar UIs is just clouding what''s going on. With that in mind I can think of two different approaches: 1. Have distinct new and edit views that pull in the drag-and-drop functionality via partials. 2. Have one popup view but pass in the url and http verb for the form postback. Here you''d give the appropriate urls for create or update. On May 5, 11:27 am, Becca Girl <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Roger Pack wrote: > > Or I''d just create it arbitrarily before the pop > > > up. Save grief :) > > As always, thanks for the great ideas. > > The pop-up is opened with link_to. When would the order be created? I > don''t think that I really want to create the order when the new order > window is opened, so I think that I''d want to create it after that. > > My thought is to put this in the controller that associated with the > pop-up window opening and it''s params. > > Also, I know this is super basic, but could someone point me to some > syntax that would create the new order and then grab the ID after the > new order is saved in the db. Order.create just creates a nil value for > ID. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> With that in mind I can think of two different approaches: > 1. Have distinct new and edit views that pull in the drag-and-drop > functionality via partials. > 2. Have one popup view but pass in the url and http verb for the form > postback. Here you''d give the appropriate urls for create or update. >Thanks for your tips. I will probably go with option 2. But just to look at one other option, does anyone know if it''s possible to use RoR and Drag and Drop without going to the server to update lists? I keep thinking that there must be some way to do this using Prototype or Javascript or something. In RoR, it looks like I might need to take a trip to the server, with the :url option, but is it possible to just keep it all on the client side? Thanks for everyone''s thoughts. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes. You could put a hidden field on the form that maps to the attribute where you store the string of ids. When you declare the droppable, add an onDrop function that pushes the id of the item onto the end of the string. I''m not sure what you''d hook for the remove (sure wish they''d fix the script.aculo.us wiki...). Good luck! On May 6, 11:19 am, Becca Girl <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> AndyV wrote: > > With that in mind I can think of two different approaches: > > 1. Have distinct new and edit views that pull in the drag-and-drop > > functionality via partials. > > 2. Have one popup view but pass in the url and http verb for the form > > postback. Here you''d give the appropriate urls for create or update. > > Thanks for your tips. I will probably go with option 2. > > But just to look at one other option, does anyone know if it''s possible > to use RoR and Drag and Drop without going to the server to update > lists? I keep thinking that there must be some way to do this using > Prototype or Javascript or something. In RoR, it looks like I might > need to take a trip to the server, with the :url option, but is it > possible to just keep it all on the client side? > > Thanks for everyone''s thoughts. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---