4

I have to display checklist of things "to do" (in spanish).

Checklist example

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!

2
  • try this: stackoverflow.com/questions/4869981/… Commented Feb 17, 2012 at 0:41
  • have you fonund the answer to this? I have the same question? Commented May 18, 2012 at 13:57

1 Answer 1

1

There might be some problems with routing, it would be better if controller is resource, put your done action in collection:

resources :controller do
  collection do
    post 'done' (or get 'done')
  end
end

Also you should try install Firebug and watch for your ajax call, maybe server just don't answer in a right way.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer Sandvich. I tried what you told me but did not make any difference... Maybe there is something wrong with the way I am writing the url... more ideas? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.