title: Rails ajax update, no route matches [POST]
body: <p>I have an app with the models Game, Ownedsq, and User, and I am trying to update a square's :user_id within a game. I have been trying this for hours now, I believe the model relationships are correct and I am just missing something small so I appreciate any help.</p>
  
  <p>Clicking on the update ownedsq button on a particular square gives me the error: <strong>No route matches [POST] "/games/2"</strong>, though I have    resources :ownedsqs in my routes.rb. My thought is maybe it isn't passing the correct ownedsq id, because I've never worked with the each_slice nesting before so maybe I messed that up.</p>
  
  <p><strong>games/show.html.erb</strong></p>
  
  <pre><code>&lt;div class="squareBoard"&gt;
      &lt;% @ownedsqs.each_slice(10) do |slice| %&gt;
          &lt;div class='row'&gt;
              &lt;% slice.each do |s| %&gt;
                  &lt;%= div_for s, class: 'sq' do %&gt;
                      &lt;%= s.boardposition %&gt;
                      &lt;%= button_to ownedsq_path(s.id), method: :put, type: 'JSON', data: {confirm: "Are you sure?"}, remote: :true %&gt;
                  &lt;% end %&gt;
              &lt;% end %&gt;
          &lt;/div&gt;
      &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>games_controller.rb</strong></p>
  
  <pre><code>def show
      require 'enumerator'
      @user = current_user
      @game = Game.find(params[:id])
      @ownedsqs = Ownedsq.all
  end
  </code></pre>
  
  <p><strong>ownedsqs_controller.rb</strong></p>
  
  <pre><code>def update
      @ownedsq = Ownedsq.find(params[:ownedsq_id])
  
      respond_to do |format|
          format.js
          if @ownedsq.update_attributes(user_id: current_user.id)
              format.html {redirect_to game_path}
              format.json {head :no_content, status: :200}
          else
              format.html {redirect_to :back}
              format.json {status: :500 }
          end  
      end 
  end
  </code></pre>
  
  <p><strong>game.rb</strong></p>
  
  <pre><code>has_many :ownedsqs
  has_and_belongs_to_many :users
  
  accepts_nested_attributes_for :ownedsqs
  
  def after_create
      1.upto(100) do |i|
        Ownedsq.create("boardposition" =&gt; i)
      end
  end
  </code></pre>
  
  <p><strong>ownedsq.rb</strong></p>
  
  <pre><code>belongs_to :user
  belongs_to :game
  </code></pre>
  
  <p><strong>user.rb</strong></p>
  
  <pre><code>has_and_belongs_to_many :games
  has_many :ownedsqs
  
  accepts_nested_attributes_for :ownedsqs
  </code></pre>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code> resources :games, :users, :ownedsqs
  </code></pre>