title: Rails 3 - Ajax Put request gives 404, yet it works
body: <p>I am updating a task status from my deal overview page where i am displaying my list of tasks for that deal</p>
  
  <p>It works, the task gets updated. However, i get a nasty 404 error.</p>
  
  <p>Any ideas?</p>
  
  <p>js/coffeescript</p>
  
  <pre><code>jQuery -&gt;
      $(".complete_task").live "click", -&gt;
      task_id = $(this).attr("value")
      alert "checkbox clicked" + task_id
      $('ul#tasks').sortable "refresh"
      $.ajax 
        url: "tasks/" + task_id
        data: "&amp;task[is_completed]=2"
        type: "PUT"
        success: -&gt;
          $(this).addClass "done"
  </code></pre>
  
  <p>My firebug output</p>
  
  <p><a href="http://img707.imageshack.us/img707/7899/screenshot20110901at102.png" rel="nofollow">http://img707.imageshack.us/img707/7899/screenshot20110901at102.png</a></p>
  
  <p>I'm open to suggestions if this is not the "right way" to do it. Though the requirement is that it must be done with ajax.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT: Requested Information</p>
  
  <p>Routing Error</p>
  
  <pre><code>&lt;h1&gt;Routing Error&lt;/h1&gt;
  </code></pre>
  
  <p><pre>No route matches {:controller=&gt;&quot;tasks&quot;, :action=&gt;&quot;show&quot;, :id=&gt;#&lt;Deal id: 1, title: &quot;4919 Torrey Pines Run&quot;, user_id: nil, created_at: &quot;2011-09-02 00:08:24&quot;, updated_at: &quot;2011-09-02 00:08:24&quot;, account_id: 1&gt;, :format=&gt;#&lt;Task id: 39, title: &quot;new tdsfsdf&quot;, position: 25, user_id: nil, deal_id: 1, created_at: &quot;2011-09-02 02:49:09&quot;, updated_at: &quot;2011-09-02 02:50:31&quot;, is_completed: 2, user_who_completed: nil&gt;}</pre></p>
  
  <p>routes</p>
  
  <pre><code>  resources :accounts do
  resources :users
  resources :deals do
    post :sort, on: :member
    resources :tasks do
      post :sort, on: :collection 
    end
  end
  </code></pre>
  
  <p>end  </p>
  
  <p>respond_to block</p>
  
  <pre><code>def update
   respond_to do |format|
     if @task.update_attributes(params[:task])
       format.html { redirect_to([@task.deal, @task], :notice =&gt; 'Task was successfully updated.') }
       format.xml  { head :ok }
       format.js   { render :nothing =&gt; true } 
  
     else
       format.html { render :action =&gt; "edit" }
       format.xml  { render :xml =&gt; @task.errors, :status =&gt; :unprocessable_entity }
       format.js   { render :nothing =&gt; true } 
  
     end
   end
  </code></pre>
  
  <p>end</p>
  
  <p>rake/grep</p>
  
  <pre><code>MacBook-Pro-2:accountable jbeasley6651$ rake routes | grep tasks
   sort_account_deal_tasks POST   /accounts/:account_id/deals/:deal_id/tasks/sort(.:format)     {:action=&gt;"sort", :controller=&gt;"tasks"}
    account_deal_tasks GET    /accounts/:account_id/deals/:deal_id/tasks(.:format)          {:action=&gt;"index", :controller=&gt;"tasks"}
                       POST   /accounts/:account_id/deals/:deal_id/tasks(.:format)          {:action=&gt;"create", :controller=&gt;"tasks"}
     new_account_deal_task GET    /accounts/:account_id/deals/:deal_id/tasks/new(.:format)      {:action=&gt;"new", :controller=&gt;"tasks"}
    edit_account_deal_task GET    /accounts/:account_id/deals/:deal_id/tasks/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"tasks"}
         account_deal_task GET    /accounts/:account_id/deals/:deal_id/tasks/:id(.:format)      {:action=&gt;"show", :controller=&gt;"tasks"}
                       PUT    /accounts/:account_id/deals/:deal_id/tasks/:id(.:format)      {:action=&gt;"update", :controller=&gt;"tasks"}
                       DELETE /accounts/:account_id/deals/:deal_id/tasks/:id(.:format)      {:action=&gt;"destroy", :controller=&gt;"tasks"}
  </code></pre>