Multiple children in single form in rails
Posted
by CaptnCraig
on Stack Overflow
See other posts from Stack Overflow
or by CaptnCraig
Published on 2010-04-10T22:35:40Z
Indexed on
2010/04/10
22:43 UTC
Read the original article
Hit count: 267
I have a model that has an arbitrary number of children entities. For simplicity lets call the entities Orders and Items. I would like to have a create Orders form where I input the order information, as well as add as many items as I want. If I click the "Add another item" button, a new set of form elements will be added to input the new data, amounts, etc..
I could hack this out in pure javascript, but I'm pretty sure there has to be a more magical, railsish way to do it, maybe with a partial view or something. I'm just a little too new to rails to know what it is.
What is the best way to dynamically add the new form elements, and then to access them in the create controller?
© Stack Overflow or respective owner