title: Cocoon Item field not posting values to database
body: <p>I have a genearted lineItem field using Cocoon gem, am having issues trying to save the line items field values,and when I inspect the elements the add_item button wasn't triggering a unique ID for each new field generated. </p>
  
  <pre><code>  class InvoicesController &lt; ApplicationController
    before_action :set_invoice,:set_line_item, only: [:show, :edit, :update, :destroy]
  
  
  def index
    @invoices = Invoice.all
  end
  
  
  def show
  
  end
  
  def new
     @invoice = Invoice.new
     @invoice.line_items.build
  end
  
  
  def edit
  
  end
  
  
   def create
   @invoice = Invoice.new(invoice_params)
  
    respond_to do |format|
     if @invoice.save
      format.html { redirect_to @invoice, notice: 'Invoice was successfully created.' }
      format.json { render :show, status: :created, location: @invoice }
     else
      format.html { render :new }
      format.json { render json: @invoice.errors, status: :unprocessable_entity }
     end
    end
   end
  
  
   def update
    respond_to do |format|
    if @invoice.update(invoice_params)
      format.html { redirect_to @invoice, notice: 'Invoice was 
      successfully updated.' }
      format.json { render :show, status: :ok, location: @invoice }
    else
      format.html { render :edit }
      format.json { render json: @invoice.errors, status: :unprocessable_entity }
     end
   end
  end
  
   def destroy
    @invoice.destroy
    respond_to do |format|
    format.html { redirect_to invoices_url, notice: 'Invoice was successfully destroyed.' }
    format.json { head :no_content }
    end
   end
  
  private
  # Use callbacks to share common setup or constraints between actions.
   def set_invoice
    @invoice = Invoice.find(params[:id])
   end
  
   def set_line_item
    @line_item = LineItem.find(params[:id])
   end
  
  # Never trust parameters from the scary internet, only allow the white list through.
  #def invoice_params
    #params.require(:invoice).permit(:total_amount,  :issue_date, :currency, :description)
  #end
  
  def invoice_params
    params.require(:invoice).permit(:amount, :date, :currency, {line_items_attributes: [:id,:quantity,:net_amount, :description, :unit_cost]})
    end
   end
  </code></pre>
  
  <p>This is my form partial view
  <a href="https://i.stack.imgur.com/DTmni.png" rel="nofollow noreferrer">enter image description here</a>    </p>
  
  <pre><code>&lt;div class="container"&gt;
      &lt;div class="row"&gt;
              &lt;div class="col"&gt;
                &lt;%= f.label :date %&gt;
                 &lt;%= f.input_field :date , class: "form-control datepicker", as: :string, id: "invoice_date" %&gt;
               &lt;/div&gt;
              &lt;div class="col"&gt;
                  &lt;%= f.label :currency %&gt;
                   &lt;%= f.input_field :currency , class: "form-control" , id: "invoice_currency" %&gt;
              &lt;/div&gt;
  
              &lt;div class="col"&gt;
                  &lt;h5&gt;Amount Due : &lt;span class="bal" id="invoice_total"&gt;679.00&lt;/span&gt;&lt;span class="subtotal_currency"&gt;
                  &lt;/span&gt;&lt;/h5&gt;
              &lt;/div&gt;
         &lt;/div&gt;
       &lt;/div&gt;
   &lt;/div&gt;
  
      &lt;table class="table"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                  &lt;th class="description"&gt;Description&lt;/th&gt;
                  &lt;th class="quantity"&gt;Quantity&lt;/th&gt;
                  &lt;th class="cost"&gt;Unit Cost&lt;/th&gt;
                  &lt;th class="price"&gt;Total Amount&lt;/th&gt;
                  &lt;th class="action"&gt;Action&lt;/th&gt;
                &lt;/tr&gt;
             &lt;/thead&gt;
              &lt;tbody class='line_items'&gt;
                &lt;div id="task"&gt;
                    &lt;%= f.simple_fields_for :line_items do |items| %&gt;
                    &lt;%= render 'line_item_fields', f: items %&gt;
                  &lt;% end %&gt;   
             &lt;/tbody&gt;
      &lt;/table&gt;
                    &lt;div class='links'&gt;
                      &lt;%= link_to_add_association 'add item', f, :line_items, class: "btn btn-primary",data: {"association-insertion-node" =&gt; "tbody.line_items", "association-insertion-method" =&gt; "append"} %&gt;
                      &lt;%= f.submit  class:"btn btn-primary" %&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;br&gt;
  </code></pre>
  
  <p>This is my nested form view</p>
  
  <pre><code>&lt;tr class="nested-fields"&gt;
    &lt;div class="container"&gt;
    &lt;div class="row row-cols-5"&gt;
      &lt;div class="col"&gt; &lt;td&gt;&lt;%= f.text_field :description, class: "form-control item_desc" %&gt;&lt;/td&gt;&lt;/div&gt;&lt;br/&gt;
      &lt;div class="col"&gt; &lt;td&gt;&lt;%= f.text_field :quantity,  class: "form-control quantity" %&gt;&lt;/td&gt;&lt;/div&gt;&lt;br/&gt;
      &lt;div class="col"&gt; &lt;td&gt;&lt;%= f.text_field :unit_cost, class: "form-control unit_cost"%&gt;&lt;/td&gt;&lt;/div&gt;&lt;br/&gt;
      &lt;div class="col"&gt; &lt;td class="price_td"&gt;&lt;%= f.text_field  :net_amount, class: "form-control price", :readonly =&gt; true %&gt;&lt;/span&gt; &lt;span class= "subtotal_currency"&gt;&lt;/span&gt;&lt;/td&gt;&lt;/div&gt;&lt;br/&gt;
      &lt;div class="col"&gt; &lt;td&gt;&lt;%= link_to_remove_association 'Delete', f, class: 'remove_record btn btn-danger' %&gt;&lt;/td&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>This is my javascript file</p>
  
  <pre><code>function update_price(){ 
      var row = $(this).parents('.nested-fields');
      var price = row.find('.unit_cost').val() * row.find('.quantity').val();
      price = price.toFixed(2);
      isNaN(price) ? row.find('.price').val('is not a number') : 
      row.find('.price').val(price);
      update_subtotal();    
  }
  
  $(document).on('cocoon:after-insert', '#task', function(added_task){
     // $('.links')
        //('cocoon:after-insert', function(e, added_task) {
         // console.log(added_task);
       // })
        $("#task").on('click', function(){
       console.log('looks like clicking works...'); //this works fine
     });
  
  });
  
  $(document).on('blur', '.unit_cost, .quantity', update_price)
  </code></pre>
  
  <p>These are the posted values to the controller</p>
  
  <p>"authenticity_token"=>"qMr1sDqfOVTdjVvXzC3Hvejh3KXnoyburvHXwu7L6Qg1mSDqnagLo0gSXrUcpJumMeb1u9pPLz9OyaYndbeqBA==", "invoice"=>{"date"=>"2019/12/06","currency"=>"Naira", "line_items_attributes"=>{"0"=>{"description"=>"rice", "quantity"=>"2", "unit_cost"=>"56", "net_amount"=>"112.00", "_destroy"=>"false"}}}, "commit"=>"Create Invoice"}
   Unpermitted parameter: :_destroy</p>