title: NestedAttributes Not Functioning
body: <p>I have Events and Songs. When a User logs in they can look at all of their events and that certain event's partycode that were created, click on one and see all the songs for that Event. Now, when the user is not logged in they can add songs to a certain event based on a certain partycode. I am unable to add fields and submit those added fields to the submit button, but I can submit the first set of fields.</p>
  
  <p>new.html.erb(Page that handles selecting an event and adding songs)</p>
  
  <pre><code>&lt;br&gt;
  &lt;br&gt;
  &lt;div class ="container"&gt;
    &lt;div class="jumbotron"&gt;
    &lt;h2&gt; Select an event to add songs to: &lt;/h2&gt;
    &lt;%= form_for Song.new do |f| %&gt;
      &lt;%= f.collection_select(:event_id, Event.all, :id, :name) %&gt;
      &lt;h3&gt; Enter your song &lt;/h3&gt;
        &lt;%= f.text_field :artist, placeholder: "Artist" %&gt;
        &lt;%= f.text_field :title,  placeholder: "Title" %&gt;
        &lt;%= f.text_field :genre,  placeholder: "Genre" %&gt;
  
      &lt;h2&gt; Enter the partycode for that event: &lt;/h2&gt;
      &lt;%= form_for Event.new do |f| %&gt;
        &lt;h4&gt;&lt;%= link_to_add_fields "Want to add more songs click here", f, :songs %&gt;&lt;/h4&gt;
  
        &lt;%= f.text_field :partycode %&gt;
        &lt;%= f.submit "Submit", class: "btn btn-primary" %&gt;
      &lt;% end %&gt;
      &lt;% end %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The link_to_add_fields method is in the application_helper.rb</p>
  
  <pre><code>module ApplicationHelper
    def link_to_add_fields(name, f, association)
      new_object = f.object.send(association).klass.new
      id = new_object.object_id
      fields = f.fields_for(association, new_object, child_index: id) do |builder|
        render("songs_fields", f: builder)
      end
      link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
    end
  end
  </code></pre>
  
  <p>The songs_fields partial is defined as follows:</p>
  
  <pre><code>&lt;fieldset&gt;
    &lt;%= text_field_tag "songs[][artist]" %&gt;
    &lt;%= text_field_tag "songs[][title]" %&gt;
    &lt;%= text_field_tag "songs[][genre]" %&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>Here is my event model: </p>
  
  <pre><code>class Event &lt; ApplicationRecord
    belongs_to :user
    has_many :songs, dependent: :destroy  
    accepts_nested_attributes_for :songs, allow_destroy: true
  
    validates :name, presence: true
    validates :partycode, presence: true, length: {minimum: 5}
  end
  </code></pre>
  
  <p>Finally, I have defined a coffeescript file for adding the extra fields:</p>
  
  <pre><code>$(document).on 'click', 'form .add_songs', (event) -&gt;
    time = new Date().getTime()
    regexp = new RegExp($(this).data('event_id'), 'g')
    $(this).before($(this).data('songs').replace(regexp, time))
    event.preventDefault()
  </code></pre>
  
  <p>All I want to do is have those extra fields be submitted to my events database which holds the songs. I have posted many questions on this matter but I haven't gotten an answer that was able to fix what I have been looking for, and after spending hours on this code I would really like to find a solution. <a href="https://i.stack.imgur.com/DOOFe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DOOFe.png" alt="enter image description here"></a></p>