title: Rails - inserting multiple records/dynamic form
body: <p>I'm working on a dynamic form in a Rails app, and I need to insert a variable number of records into a model in a single form submission.  I've done this using PHP -> MySQL/Postgres before, but I have no idea how to do it in Rails.</p>
  
  <p>Ultimately, users should be able to create any number of records to be inserted, but in my example below, I'm limiting it to 2... let me see if I can do that, first...</p>
  
  <p>Here's the form - the ids all get a unique suffix because they are being populated dynamically from localStorage objects on submission.</p>
  
  <p>new.html.erb</p>
  
  <pre><code>&lt;%= form_for @entry, html: {id: :new_entry_form} do |f| %&gt;
      &lt;% for i in 0..1 %&gt;
          &lt;%= f.text_field :name, :id =&gt; 'name_#{i}' %&gt;
          &lt;%= f.text_field :day, :id =&gt; 'day_#{i}' %&gt;
      &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Here's the associated controller - <em>I'm sure</em> that this is missing something, but I don't know what.</p>
  
  <pre><code>def new
      @entry = Entry.new
  end
  
  def create
      @entry = Entry.create(entry_params)
      redirect_to "http://localhost:3000/entries"
  end
  
  private
  def entry_params
      params.require(:entry).permit(:name, :day)
  end
  </code></pre>
  
  <p>Any help would be much appreciated.</p>