Robert Hulme
2006-Jul-21 14:15 UTC
[Rails] How can I create OrderItems that go in a Order?
I suspect my problem is similar to having an order and wanting to have order items as part of the order, so I''ll explain the problem in those more familiar terms and then explain what if anything makes my actual situation different at the end. In an Order lets say you have: shipping_address and a shipped bool. OrderItem has quantity and name So Order has_many :OrderItems, and OrderItem belongs_to :Order It''s pretty easy to make it so you can create an Order then go to another URL and create a OrderItem and associate (say with a select) the Order the OrderItem belongs to, and so on. What I really want though is the ability to have users click to create an Order, fill out those fields, then on the same page fill out the details for the first OrderItem and be able to click say a + or a ''Add another'' link or something and add another OrderItem and so on. This is so common there must be a tutorial or example somewhere that someone can point me at so I can RTFM? I have (I think) all the Pragmatic Programmers Rails books if there is a section in there I''ve missed. I was also wondering how to make it so that you can''t have an Order in existence that has no OrderItems, in the sense that I don''t want Orders floating around that makes no sense. I can think of ways maybe of doing this - but not with everything on one page. The actual problem I have is I think quite similar. I am implementing a ''Requisition'' system at work - where a requisition is like an order (it has a supplier, user who requested it, user who approved it etc), and contains a list of items that the user wants requisitioned. Thanks! -Rob -- ------------------------------------------------------ "On two occasions, I have been asked [by members of Parliament], ''Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?'' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage (1791-1871) "98.5% of DNA is considered to be junk DNA with no known purpose. Maybe it''s XML tags." -- Anon http://www.robhulme.com/ http://robhu.livejournal.com/
Robert Hulme
2006-Jul-22 20:30 UTC
[Rails] Re: How can I create OrderItems that go in a Order?
> This is so common there must be a tutorial or example somewhere that > someone can point me at so I can RTFM? I have (I think) all the > Pragmatic Programmers Rails books if there is a section in there I''ve > missed.Is this not possible in Rails? -- ------------------------------------------------------ "On two occasions, I have been asked [by members of Parliament], ''Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?'' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage (1791-1871) "98.5% of DNA is considered to be junk DNA with no known purpose. Maybe it''s XML tags." -- Anon http://www.robhulme.com/ http://robhu.livejournal.com/
@new_order_item = Order.orderitem.create( :quantity => ''20'' ) -- Posted via http://www.ruby-forum.com/.
Jan wrote:> @new_order_item = Order.orderitem.create( :quantity => ''20'' )oops @new_order_item = Order.find( params[:id] ).orderitems.create( :quantity => ''20'', :name => ''example'' ) -- Posted via http://www.ruby-forum.com/.