title: Rails change boolean value with checkbox and jquery ajax
body: <p>I am new to rails and trying to change the value of a boolean via a checkbox and using jquery ajax:</p>
  
  <pre><code>&lt;%- @tasks.each do |task| %&gt;
    &lt;div class="task-wrapper"&gt;
      &lt;%= check_box_tag 'completed', task.id , task.completed, :class =&gt; "task-check" %&gt;
      &lt;%= content_tag :span, task.task %&gt;
      &lt;%= content_tag :span, task.deadline %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>and the javascript:</p>
  
  <pre><code>$(".task-check").bind('change', function(){
    if (this.checked){
      var bool = this.checked ? 1 : 0;
      $.ajax({
        url: '/todos/toggle',
        type: 'POST',
        data: '{"task_id":"'+ this.value +'", "bool":"'+ bool +'"}'
      });
    }
    else {
      alert("no");
    }
  });
  </code></pre>
  
  <p>then the controller:</p>
  
  <pre><code>def toggle(task_id, bool)
    @task = Todo.find_by_id(task_id)
  
    if @task != nil?
      @task.update_attributes(:completed =&gt; bool)
    else
      set_flash "Error, please try again"
    end
  end
  </code></pre>
  
  <p>finally the routes:</p>
  
  <pre><code>resources :todos do
    member do
      post 'toggle'
    end
  end
  </code></pre>
  
  <blockquote>
    <p>also tried collection but gives the same error.</p>
  </blockquote>
  
  <p>when ever i try it i get a <code>404 error</code> on the action.</p>
  
  <p>what is the problem?</p>
  
  <p>thanks</p>