Ask A Question

Notifications

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.

routes.rb

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

task_controller

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

done.js.erb

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

tasks/index (_index.js.erb)

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

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

Reply
Join the discussion
Create an account Log in

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

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

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