2

I want to create several instances of same model form a single form. And more importantly, the number of instances aren't known before form rendering.

I've seen several tutorials of this kind, but unfortunately those didn't suit my need. I've seen Ryan bate's nested form tutorial. But I'm not creating nested form. I've also seen some tutorials, which do create multiple objects, but the number of object's are all known in those cases. One of the tutorial is here - http://archive.railsforum.com/viewtopic.php?id=717

User will click a button and a new set of fields for a new object will be inserted just like the nested form demo from ryanb.

Here is a mockup of what I want. It's basically a very small form fit into a single line.

enter image description here

Anwar
  • 1,755
  • 1
  • 21
  • 32

2 Answers2

0

As i understand you need cocoon gem it allows to add form fields

sts
  • 380
  • 3
  • 11
-1

It sounds like you may need to reach beyond Rails views and utilize javascript to dynamically render more "partials" when the user decides to add more fields. Something like this: Adding input elements dynamically to form

If you want to keep your view rendering logic in rails, you could make an AJAX request to your application, have it return just a partial's worth of html back, and insert the response html into your dom.

Community
  • 1
  • 1
Inanepenguin
  • 178
  • 1
  • 2
  • 9