I have to display checklist of things "to do" (in spanish).
The idea is once the checkbox associated to an item is checked, the text of the label gets a line through (text-decoration:line-through) and an attribute (named: done) from the database gets updated.
To do this I have the following:
In my view:
<% @user_account.activities.each do |act| %>
<div class="checklist_check">
<%= check_box_tag 'activity_status', act.id, act.done, :class => 'activity_status' %>
<%= act.name %>
</div>
<% end %>
In the javascript:
$(function(){
$(".activity_status").live("change", function(act_id) {
$.ajax({
url: "/controller/done",
beforeSend: function() { alert("Hi") },
data: "id="+act_id,
success: function() { alert('Bye') }
});
});
});
In my controller:
def done
@activity = Activity.find params[:id]
if @activity.done
@activity.update_attributes :done_by_date, false
else
@activity.update_attributes :done_by_date, true
end
end
Also I set up the route for this action: get "controller/done"
The problem:
Once I click on a checkbox the function gets called and the alert("hi") gets executed but the success function does not and the "done" attribute never gets updated in the database.
Any ideas of what am I doing wrong? How would you do it?
Thanks in advance!