I am trying to create on my view the submission of a checkbox (it's a toggle of an attribute) by only clicking the checkbox itself, and without having to use the submit button.
This is what I have for my text box/submit:
<%= form_for @task, remote: true do |task| %>
<%= task.check_box :complete, class: "check_box" %>
<%= task.submit %>
<% end %>
When I only click the box, I would like to trigger this method:
def update
@task = Task.find(params[:id])
@task.toggle :complete
@task.save
respond_to do |format|
format.html
format.js
end
end
I'm wondering if any of you think that creating a link_to with a div would be an easier solution to this problem, otherwise I would like to use jquery or some other method and keep the check box.
Thank you!