For a personal invoicing app in rails I could use some advice on the following: In a new invoice form, how to dynamically add a new row consisting of a collection_select for products
and an associated text_field for amount
by clicking add new product
?
Since one invoice has many products and a product has many invoices, I figured this is a HABTM relationship both ways. Therefore I have created the tables invoices
, products
, and their join table invoices_products
.
I would like the invoices/new
page to have a form where a user can use a collection_select to pick a product (all products are already preloaded in the products
table) and fill in the amount in a text field behind it.
A user should be able to duplicate these two fields (collection_select and text_field) by clicking add new product
, something like RailsCast #403 Dynamic Forms 04:50
.
Now how would I go about doing that? And in what table would I put the data from the amount
text_field, since there are multiple products per invoice so multiple amounts?
Any answer in the right direction will be greatly appreciated!