All threads / How to complete a task via json using a check_box?
Ask A Question


You’re not receiving notifications from this thread.

How to complete a task via json using a check_box?

rodolfo asked in General

Hi guys,
I am new in this world of web development. I'm trying to mark a task as complete using a check_box, but I can't. Have you any ideas based on my code? Thank you in advance.


resources :commitments do
    resources :tasks  do
        member do
            patch :done


def done
    @task = Task.find(params[:id])
    @task.update_attribute(:done, true)


$('#task #task-<%= %>').html("<%= j render 'tasks/index' %>")

tasks/index (_index.js.erb)

<% @commitment.tasks.each do |task|%>
<div class="row" id="task-<%= %>">
    <div class="form-group col">
        <span class="checklist-reorder">
            <i class="material-icons">reorder</i>
        <div class="custom-control custom-checkbox col">

                        <!-- space for the check_box_tag -->
            <input type="checkbox" class="custom-control-input" id="checklist-item-<%= %>" checked>
            <label class="custom-control-label" for="checklist-item-<%= %>"></label>
                <input type="text" placeholder="Checklist item" value="<%= %>" data-filter-by="value" />
                <div class="checklist-strikethrough"></div>
                <%= link_to 'delete', commitment_task_path(, task), method: :delete, remote: true %>
<% end %>

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.