title: Rails: Updating Nested attributes - undefined method `to_sym' for nil:NilClass
body: <p><strong>Edit:</strong> Added the update action, and on what line the error occurs</p>
  
  <p>Model:</p>
  
  <pre><code>class Match &lt; ActiveRecord::Base  
    has_and_belongs_to_many :teams
    has_many :match_teams
    has_many :teams, :through =&gt; :match_teams
    accepts_nested_attributes_for :match_teams, :allow_destroy =&gt; true
  end
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>  def new
      @match = Match.new
      @match_teams = 2.times do
        @match.match_teams.build
      end
  
      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @match }
      end
    end
  
    def update
      @match = Match.find(params[:id])
  
      respond_to do |format|
        if @match.update_attributes(params[:match])
          format.html { redirect_to @match, notice: 'Match was successfully updated.' }
          format.json { head :ok }
        else
          format.html { render action: "edit" }
          format.json { render json: @match.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>Nested model:</p>
  
  <pre><code>class MatchTeam &lt; ActiveRecord::Base
    belongs_to :match
    belongs_to :team
  end
  </code></pre>
  
  <p>Association:</p>
  
  <pre><code>class Team &lt; ActiveRecord::Base
    has_and_belongs_to_many :matches
  end
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;%= form_for(@match) do |f| %&gt;
  
    &lt;%= f.fields_for :match_teams, @match_teams do |builder| %&gt;
      &lt;%= builder.collection_select :team_id, Team.all, :id, :name, :include_blank =&gt; true %&gt;
    &lt;% end %&gt;
  
    &lt;% unless @match.new_record? %&gt;
      &lt;div class="field"&gt;
        &lt;%= f.label :winning_team_id %&gt;&lt;br /&gt;
        &lt;%= f.collection_select :winning_team_id, @match.teams, :id, :representation %&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Params:</p>
  
  <pre><code>Processing by MatchesController#update as HTML
  Parameters: {"utf8"=&gt;"Ô£ô", "authenticity_token"=&gt;"QIJChzkYOPZ1hxbzTZS8H3AXc7i
  BzkKv3Z5daRmlOsQ=", "match"=&gt;{"match_teams_attributes"=&gt;{"0"=&gt;{"team_id"=&gt;"1", "
  id"=&gt;""}, "1"=&gt;{"team_id"=&gt;"3", "id"=&gt;""}}, "winning_team_id"=&gt;"3"}, "commit"=&gt;"
  Update Match", "id"=&gt;"2"}
  </code></pre>
  
  <p>Creating a new match with 2 teams work fine, the edit view also shows the correct values, but the update action gives me this error.</p>
  
  <pre><code>undefined method `to_sym' for nil:NilClass
  app/controllers/matches_controller.rb:65:in `block in update'
  
  line 65: if @match.update_attributes(params[:match])
  </code></pre>