Dynamic Field Forms in Rails?

Asked

Viewed 280 times

0

For my TCC project, I have the following specification:

A user, to register a production item, must inform all its ingredients. To facilitate interaction, I thought of, list all ingredients registered in checkboxes. When the user clicks on a certain link, a Javascript function will count the checkboxes marked, and then create in a div the text fields corresponding to each ingredient so that the user can enter the amount of each one.How accidental markings can happen, in the div with inputs, it should still be possible for the user to delete unwanted fields by clicking on a link.

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

  • Hello, are you using version 4.1? Please enter your code! : D Thanks!

  • Hi @Brunocasali I haven’t started implementing yet. I’m researching the best approach, and if this is possible before starting. As for your first question, yes, I am using the 4.1.

  • 1

    Dude I’m starting with Rails too, I haven’t had to do this kind of form yet, I just had a few disagreements with forms of more than one model. But I found some links that I think can help you, comp-groups, stack, looked up 'Dynamic Forms in Rails 4' :D

1 answer

1

Rails will receive the value of any element that:

  1. is inside the form
  2. has the name property filled, even if dynamically created.

Since you are using 4.1, Strong Parameters will force you to release the valid parameter names, take this into account.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.