title: Rails Nesteds Forms with dynamic fields
body: <p>Assuming I have a recipe table that has a field for name. The form would look something like this:</p>
  
  <pre><code>&lt;%= form_with(model: recipe, local: true) do |form| %&gt;
    &lt;%= form.text_field :name %&gt;
    &lt;%= form.submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>but if recipe is related to  ingredients (which contains a name fields) through an intermediate table with the amount of the ingredient.
  how should i do the form to create a recipe, choose the ingredient and enter the amount of the ingredient. And also have the option to generate more fields if the recipe has more than one ingredient. All that in one form.
  Something like that:</p>
  
  <pre><code>&lt;%= form_with(model: recipe, local: true) do |form| %&gt;
  
    &lt;%= form.text_field :name %&gt;
  
    (select field to choose an ingredient)
  
    (field for recipe_ingredient to ingress the amount of the ingredient)
  
    (button to generate more fields for other ingredients)
  
    &lt;%= form.submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>rails version: 5.2.2</p>