Skip to main content

Orders and Order Items

General • Asked by Michael Victor

I have 2 models, Orders and Order Items.

I want the user to be able to add any number of items to an order in the view. How can I structure a form so that I can iterate over the order items or is there a better way I could go about this?


Basically you're wanting to build a nested form, where you have one main item (the Order) and many nested items underneath it (the OrderItems). Cocoon is a cool little library that lets you dynamically add those nested items to the form. It might do what you're looking for: https://github.com/nathanvda/cocoon


Exactly what I was looking for! Thank you so much Chris!


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.