All threads / Orders and Order Items

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Orders and Order Items

Michael Victor asked in General

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!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,665+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.