title: Rails has_many form optionally create multiple records
body: <p>I have a <code>Profile</code> model and I'm trying to see if that profile has used any other names in the past. I came up with adding a <code>AdditionalName</code> model, and the association is <code>Profile has_many AdditionalName</code>. In the form, I would like for them to fill out up to 5 additional names. I saw from <a href="https://stackoverflow.com/questions/45533686/create-multiple-records-with-fields-for-rails">this question</a> I can build it <code>x.times</code> and use <code>f.fields_for :additional_names</code> to show 5 additional names. Problem is, it will save all 5 when I submit the form, even if they don't fill anything. Is it possible that the <code>AdditionalName</code> records only save when they fill out something in the input field?</p>
  
  <p>additional_name.rb</p>
  
  <pre><code>class AdditionalName &lt; ApplicationRecord
    belongs_to :profile
  end
  </code></pre>
  
  <p>profile.rb</p>
  
  <pre><code>class Profile &lt; ApplicationRecord
    has_many :additional_names
    accepts_nested_attributes_for :additional_names
  end
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>def new
  existing_additional_names = @profile.additional_names.count
  (5 - existing_additional_names).times do
    @current_object.additional_names.build
  end
  </code></pre>
  
  <p>form:</p>
  
  <pre><code>&lt;%= form_with model: @profile, url: wizard_path, method: :patch, local: true do |f| %&gt;
    &lt;div class="form-row"&gt;
      &lt;%= f.fields_for :additional_names do |additional_names_form| %&gt;
        &lt;%= additional_names_form.hidden_field :id %&gt;
        &lt;div class="form-group col-md-6"&gt;
          &lt;div class="mx-auto"&gt;
            &lt;%= additional_names_form.label :name, "Full name" %&gt;
            &lt;%= additional_names_form.text_field :name, class: "form-control", id: "ignore-button-disable" %&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;% end %&gt;
    &lt;/div&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-md-6 my-2"&gt;
        &lt;%= f.submit 'Continue', class: 'btn btn-primary w-100' %&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>