title: Rails3 Update Boolean Checkbox from Index View
body: <p>I'm building a simple tasks application for our company as part of an ordering system.</p>
  
  <p>I have a list of tasks with a number of rules. Nothing complex... What I'm stuck on is the addition of a checkbox to complete the task. I want it done live, from the index view without having to hit submit..</p>
  
  <p>Am really not sure even where to look. I figure I need to use ajax to do this - can anyone recommend a tutorial or tell me what I should be looking for.</p>
  
  <p>Have also thought about a plugin, like the edit in place ones out there.</p>
  
  <p>Thanks in advance </p>
  
  <p>--- EDIT 1 -- </p>
  
  <p>Following advice from @pcg79 below, I've added the following to my application but am not understanding how I go out actually changing the status.</p>
  
  <p>In my index view I have this:</p>
  
  <pre><code>&lt;%= check_box_tag 'complete_task_1', '', false, { 'data-href' =&gt; tasks_path(@task) } %&gt;&lt;
  </code></pre>
  
  <p>I've added the following to my application.js (added a # to get it to call properly) </p>
  
  <pre><code> $('#complete_task_1').click(function() {
    $.ajax({
      url: $(this).data('href'),
      type: 'PUT',
      dataType: 'html',
      success: function(data, textStatus, jqXHR) {
        // Do something here like set a flash msg
      }
    });
  });
  </code></pre>
  
  <p>For lack of understanding, I added this to my tasks controller:</p>
  
  <pre><code>def completed 
      @task = Task.find(params[:id])
      @task.status = true
   end
  </code></pre>
  
  <p>Which seemed reasonable but wasn't sure how to actually call that in the ajax?</p>
  
  <p>In my development log I can see it sort of working but it says this:</p>
  
  <pre><code>ActionController::RoutingError (No route matches "/tasks"):
  </code></pre>
  
  <p>-- EDIT 2 --</p>
  
  <p>As per advice from @jdc below, I've tried adding the following to routes.rb:</p>
  
  <p>get 'tasks/:id/completed' => 'tasks#completed', :as => :completed_task</p>
  
  <p>But still get the RoutingError. </p>
  
  <p>-- Slight Update --</p>
  
  <p>Following the excellent advise from @pcg79 below, I've updated my files with the following.</p>
  
  <p>Routes.rb</p>
  
  <blockquote>
    <p>get 'task/:id' => 'tasks#completed', :as => :completed_task</p>
  </blockquote>
  
  <p>Index.html.erb</p>
  
  <pre><code>&lt;td&gt;&lt;%= check_box_tag 'complete_task_1', '', false, { 'data-href' =&gt; completed_task_path(:id =&gt; task.id) } %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Tasks controller</p>
  
  <pre><code>def completed 
      @task = Task.find(params[:id])
      @task.status = true
      @task.save
    end
  </code></pre>
  
  <p>I get no errors in my browser, but my development log shows this:</p>
  
  <pre><code>ActionController::RoutingError (No route matches "/tasks"):
  </code></pre>
  
  <p>For a simple checkbox, this is hard work!!!</p>
  
  <p>-- Another update --</p>
  
  <p>Having played all day, I decided to see what would happen with a button_to instead, forgetting the ajax side of things. I put this in my code:</p>
  
  <pre><code>&lt;%= button_to "Complete", completed_task_path(task.id) %&gt;
  </code></pre>
  
  <p>And changed routes to:</p>
  
  <pre><code>match 'tasks/:id/completed' =&gt; 'tasks#completed', :as =&gt; :completed_task
  </code></pre>
  
  <p>Which worked a treat. Changing back to check_box_tag breaks it all again :(</p>
  
  <p>Pretty much worked out it's the contents of my function. Having removed some code, I can update the css for a #:</p>
  
  <pre><code> $('#complete_task_1').click(function() {
    $.ajax({
      success: function(data, textStatus, jqXHR) {
          $('#thing').css("color","red");
      }
    });
  });
  </code></pre>
  
  <p>Any idea what I'd need to call my action?? J</p>