title: Saving multiple records with a single form in Rails 4
body: <p>I have a model called <code>Family</code>, which <code>belongs_to :user</code>
  I want to enable the user to add multiple family members in a single form, which is in <code>/views/families/new.html.erb</code></p>
  <ul>
  <li>So the user sees a form for creating 3 family members for one user_id</li>
  <li>Enters data into 3 identical forms, and hits submit</li>
  <li>The data from <strong>3 individual forms should get saved as 3 different records in the db on submitting just once</strong></li>
  <li>Now, when I submit the form, all values in the db are saved as NULL.</li>
  <li>What am I doing wrong? Should I not use strong params?</li>
  </ul>
  <p>EDIT:  Sorry, I should've provided more detailed code earlier
  after slight modification in code</p>
  <pre class="lang-rb prettyprint-override"><code># config/routes.rb
  resources :families
  </code></pre>
  <pre class="lang-rb prettyprint-override"><code>#app/models/user.rb 
  class User &lt; ActiveRecord::Base
    has_many :families
  end
  </code></pre>
  <pre class="lang-rb prettyprint-override"><code>#app/models/family.rb
  class Family &lt; ActiveRecord::Base
    belongs_to :user
  end
  </code></pre>
  <pre class="lang-rb prettyprint-override"><code>#app/controllers/families_controller.rb
  class FamiliesController &lt; ActiveRecord::Controller
    def new
    end
    
    def create
      @family = Family.new(family_params)
      a = params[:family][:&quot;0&quot;]
      @family.user_id = current_user.id
      if @family.save
        flash[:notice] = params[:family][:&quot;0&quot;]
        redirect_to dummy_path
      else
        flash[:notice] = &quot;didnt happen&quot;
      end
    end
    
    private
    
    def family_params
      params.require(:family).permit(:all)
    end
  end
  </code></pre>
  <pre><code>#app/views/families/_form.html.erb
  &lt;%= form_tag(controller: &quot;families&quot;) do %&gt;
    &lt;% i = 0 %&gt;
    &lt;% 3.times do %&gt;
      &lt;br&gt;
      &lt;h2&gt;Family Member # &lt;%= i+1 %&gt; : &lt;/h2&gt;
      &lt;br&gt;
      &lt;%= fields_for(&quot;family[#{i}]&quot;) do |f| %&gt;
          &lt;%= f.text_field :name, class: &quot;form-control&quot; , placeholder: &quot;Name&quot;%&gt; &lt;br&gt;
          &lt;%= f.text_field :relationship, class: &quot;form-control&quot; , placeholder: &quot;Relationship&quot; %&gt; &lt;br&gt;
          &lt;%= f.date_field :dob, class: &quot;form-control&quot; %&gt; &lt;br&gt;
          &lt;%= f.text_field :blood_group, class: &quot;form-control&quot;, placeholder: &quot;Blood group&quot; %&gt; &lt;br&gt;
          &lt;%= f.text_field :email, class: &quot;form-control&quot;, placeholder: &quot;Email&quot; %&gt; &lt;br&gt;
          &lt;%= f.number_field :phone, class: &quot;form-control&quot;, placeholder: &quot;Phone number&quot; %&gt; &lt;br&gt;
          &lt;%= f.text_area :hobbies, class: &quot;form-control&quot;, placeholder: &quot;Hobbies&quot; %&gt; &lt;br&gt;
          &lt;% i=i+1 %&gt;
      &lt;% end %&gt;
      &lt;hr&gt;
    &lt;% end %&gt;&lt;br&gt;
    &lt;%= submit_tag &quot;Submit&quot;, class: &quot;btn btn-primary&quot; %&gt; &lt;br&gt;
  &lt;% end %&gt;
  </code></pre>