Ilegorika
Ilegorika

Reputation: 13

Create/Update Multiple Many-to-Many Records Through Single Form

I'm trying to create a system similar to the functionality of an ecommerce system. A table is displayed with a list of products, with a text boxes for entering the desired quantity of each product. At the bottom of the table is a button to process the purchase, this should then create an Inventory record for each of the products with a quantity of more than 0, unless a record already exists for that customer, in which case it should increment it by the stated value.

I have absolutely no idea how to even begin doing this in Rails, or what to search for to find answers, any pointers in the right direction would be great. I have a lot of experience with C-style languages, but RoR is very different and I just don't know where to begin with this.

Associations:

Customer

Inventory

Product

Upvotes: 1

Views: 845

Answers (1)

MDaubs
MDaubs

Reputation: 3004

These are called nested forms. Ryan Bates probably has the best crash course on the topic:

http://railscasts.com/episodes/196-nested-model-form-part-1

http://railscasts.com/episodes/197-nested-model-form-part-2

Upvotes: 1

Related Questions