Rails check_box_tag how to pass value when checked ajaxily

后端 未结 4 1824
死守一世寂寞
死守一世寂寞 2021-01-01 03:58

On my index page for my Task model, I want to show a checkbox for every row that corresponds to the boolean field \"complete\" in my Task database table.

Currently m

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 04:50

    If you are using jQuery, you can write a click event.

    $('.input-large').click(function() {
      var checked; 
      if ($(this).is(':checked')) {
        checked = true;
      } else {
        checked = false;
      } 
      $.ajax({
          type: "POST",
          url: "/tasks/complete",
          data: { id: $(this).data('post-id'), checked: checked }
       });     
    });
    

提交回复
热议问题