Rails check_box_tag how to pass value when checked ajaxily

后端 未结 4 1799
死守一世寂寞
死守一世寂寞 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:36

    The suggestion from this issue in rails/jquery-ujs github repo worked for me: https://github.com/rails/jquery-ujs/issues/440#issuecomment-197029277

    For you it would be:

    <%= check_box_tag 'complete', '1', task.complete, {
      onchange: "$(this).data('params', 'complete=' + this.checked)",
      data: { url: url_for(action: 'complete', id: task.id,), remote: true, method: :patch },
    } %>
    

提交回复
热议问题