title: Getting undefined method `values_at' for nil:NilClass using nested_form_for
body: <p>I'm using nested_form gem from ryanb and it doesn't seem to be working properly. The remove link doesn't work (I installed the //= require jquery_nested_form properly and it looks like it's loading but i keep getting this error:</p>
  
  <pre><code>undefined method `values_at' for nil:NilClass
  </code></pre>
  
  <p>when i go to add:</p>
  
  <pre><code>= f.link_to_add "Add a line item", :invoice_line_items
  </code></pre>
  
  <p>also, without that line it works but the remove link doesn't do anything: </p>
  
  <pre><code>line_item.link_to_remove "Remove this line item"
  </code></pre>
  
  <p>here's my code:</p>
  
  <pre><code>.row-fluid
    .span10.offset1
      = nested_form_for(@invoice) do |f|
        - if @invoice.errors.any?
          #error_explanation
            %h2
              = pluralize(@invoice.errors.count, "error")
              prohibited this invoice from being saved:
            %ul
              - @invoice.errors.full_messages.each do |msg|
                %li= msg
        .fieldset
          %legend
            = "New Invoice for #{@client.name}"
          .form-horizontal
            .pull-left
              .control-group
                %label.control-label{:style =&gt; "width: 100px;"}
                  Invoice ID
                .controls{:style =&gt; "margin-left: 120px;"}
                  = f.text_field :client_invoice_id, :class =&gt; "input-small", :placeholder =&gt; @invoice_count_placeholder
              .control-group
                %label.control-label{:style =&gt; "width: 100px;"}
                  Due Date
                .controls{:style =&gt; "margin-left: 120px;"}
                  = f.select :payment_term, @payment_terms, { :required =&gt; "true" }, { :class =&gt; "span10" }
            .pull-right
              .control-group
                %label.control-label
                  Issue Date
                .controls{:style =&gt; "margin-right: 60px;"}
                  = f.text_field :issue_date, :id =&gt; "date-picker", :class =&gt; "input-small", :required =&gt; "true"
              .control-group
                %label.control-label
                  Discount
                .controls{:style =&gt; "margin-right: 60px;"}
                  .input-append
                    = f.text_field :discount, :class =&gt; "input-small", :placeholder =&gt; "Optional"
                    %span.add-on %
          .row-fluid
            %table.table
              = f.fields_for :invoice_line_item do |line_item|
                %tr
                  %th
                  %th.span8 Description
                  %th.span1 Quantity
                  %th.span1 Rate
                  %th.span1 Amount
                %tr
                  %td= line_item.link_to_remove "Remove this line item"
                  %td= line_item.text_field :description
                  / %td= text_area_tag 'body', nil, :style =&gt; "width:96%;"
                  %td= text_field_tag 'hello', nil, :class =&gt; "input-mini"
                  %td= text_field_tag 'hello', nil, :class =&gt; "input-mini"
                  %td $99.99
  
              = f.link_to_add "Add a line item", :invoice_line_items
          .form-actions
            = f.submit "Preview Invoice", :class =&gt; "btn btn-primary pull-right"
  </code></pre>
  
  <p>any idea what i'm doing wrong? I want to easily be able to add line items to the invoice and then save the whole thing. Here's my associations:</p>
  
  <pre><code>class Invoice &lt; ActiveRecord::Base
    ## ASSOCIATIONS ##
    belongs_to :user
    belongs_to :client
    has_many :invoice_line_items
    ## NESTED ATTRIBUTES ##
    accepts_nested_attributes_for :invoice_line_items, :allow_destroy =&gt; true
  
  class InvoiceLineItem &lt; ActiveRecord::Base
    ## ASSOCIATIONS ##
    belongs_to :invoice
  </code></pre>
  
  <p>EDIT: here's my invoices controller new action:</p>
  
  <pre><code>def new
      @client = current_user.clients.find(params[:client_id])
      @invoice = Invoice.new(:client_id =&gt; @client.id)
      @payment_terms = Invoice.payment_terms
  
      if @client.invoices.count &gt; 0
        @invoice_count_placeholder = "Last used: #{@client.invoices.last.client_invoice_id}"
      else
        @invoice_count_placeholder = ""
      end
  
      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @invoice }
      end
    end
  </code></pre>