title: Ajax Posting via jQuery to custom controller method not working
body: <p>I'm having an issue posting data to my custom controller methods via a jquery ajax post.</p>
  
  <p>I have the following rails myPlayer.erb.html:</p>
  
  <pre><code>&lt;% form_for @playersonline, :url =&gt;  game_index_path, :html =&gt; { :method =&gt; :put, :class =&gt; "block", :id =&gt; "playersOnline_form" } do |f| %&gt;
  
          &lt;% @playersonline.each do |member| %&gt;
  
            &lt;li&gt;
              &lt;div class="playerDetails"&gt;
                &lt;div class="playerNickname"&gt;&lt;%= member.nickname %&gt;&lt;/div&gt;
                &lt;div class="playerPlayLink"&gt;
                  &lt;input type="button" class="submit_button playPlayer" id="&lt;%= member.nickname %&gt;" value="Play" /&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/li&gt;
  
          &lt;% end %&gt;
  
          &lt;p class="morePlayers"&gt;  
            &lt;a href=""&gt;View more players &gt;&gt;&lt;/a&gt;
          &lt;/p&gt;
  
        &lt;% end %&gt;
  </code></pre>
  
  <p><br />The forms html looks like this when rendered:</p>
  
  <pre><code>&lt;form accept-charset="UTF-8" action="/game" class="block" id="playersOnline_form" method="post"&gt;
  </code></pre>
  
  <p><br />
  And the following jQuery code that attaches event handllers to each button.</p>
  
  <pre><code>SITE.Game = function() {
  
    $('.playPlayer').live('click', 
      function() { 
        SITE.Game.sendGameRequest() 
      } 
    );
  }
  
  SITE.Game.sendGameRequest = function() {
  
    $.post('/game/test,{"testData": "One", "testDataAgain": "Two"}, function(result) { console.log("data returned = " + result); }, "json")
  
  } 
  </code></pre>
  
  <p><br />
  So when I click a button, and the event fires making the ajax request I get the following error back:</p>
  
  <pre><code>Started POST "/game/test" for 127.0.0.1 at 2011-03-13 00:05:59 +0000
  
  ActionController::RoutingError (No route matches "/game/test"):
  </code></pre>
  
  <p><br />
  My controller looks like this, and I can see from the server output that its not going into my test method:</p>
  
  <pre><code>class GameController &lt; ApplicationController
  
    def test
      puts "---------------------------"
      puts "GAME TEST WORKING"
      puts "---------------------------"  
    end
  
    def index  
  
      @returnMember = ["Tom","Pete"]
  
      respond_to do |format|
        format.json { render :json =&gt; @returnMember.to_json }
      end
    end
  
  end
  </code></pre>
  
  <p>I have the following in my routes also:</p>
  
  <pre><code>resources :game
  </code></pre>
  
  <p>Any ideas where I'm going wrong?</p>
  
  <h2>EDIT</h2>
  
  <p>In response to nzifnab reply. I added:</p>
  
  <pre><code>resource :game do
    member do
      post 'test'
    end
  end
  </code></pre>
  
  <p>But am now getting:</p>
  
  <pre><code>ActionController::RoutingError (uninitialized constant GamesController):
  </code></pre>
  
  <h2>EDIT 2</h2>
  
  <p>Fixed above by changing controller to GamesControllor from GameController.</p>
  
  <p>Now getting the error:</p>
  
  <pre><code>undefined local variable or method `games_index_path'
      &lt;% form_for @playersonline, :url =&gt;  games_index_path, :html =&gt; { :method =&gt; :put, :class =&gt; "block", :id =&gt; "playersOnline_form" } do |f| %
  
  &gt;
  </code></pre>
  
  <p>See my controller at beginning of issue.</p>
  
  <h2>EDIT 3</h2>
  
  <p>Fix for Edit 2 is quite simple! Changed url to games_path</p>