Dynamic Field Forms in Rails?

0

For my CBT project, I have the following specification:

A user, to register a production item, needs to report all of their ingredients. To facilitate the interaction, I thought of, listing all the ingredients registered in checkboxes. When the user clicks on a certain link, a JavaScript function will count the marked checkboxes, and from there will create in a div the text fields corresponding to each ingredient so that the user can enter the quantity of each one. How accidental markings can happen , in the div with the inputs, it should still be possible for the user to delete the unwanted fields by clicking on a link.

My question is about the back end. How can I save this in the database? How will I capture the quantities in each field if they are not previously created in the .html.erb file?

    
asked by anonymous 02.07.2014 / 16:03

1 answer

1

Rails will get the value of any element that:

  • is within the form
  • have the name property populated, even if dynamically created.
  • As you are using 4.1, the strong parameters will force you to release valid parameter names, keep that in mind.

        
    02.07.2014 / 19:05