Right now, I am able to create objects and save them to a rails database 
through a json api. It is a simple todo list app that when I add an object, 
it goes into the todo list above the input fields. I am also able to query 
all the objects on the index view and list all of my todo objects.

When I click on a checkbox next to each todo item, it is supposed to change 
it's :done attribute to true, so that I do not show it anymore after they 
click a "Clear" button which is the clearCompletedfunction.

Here is my js code

angular.module("Todo", ["ngResource"])
function TodoController($scope, $filter, $resource) {
  Todo = $resource("/todos.json", {id: "@id"}, {update: {method: 'PUT'}})
    $scope.todos = Todo.query()

  $scope.getTotalTodos = function () {
      return $scope.todos.length;
  };

  $scope.clearCompleted = function () {
    Todo.save({done:true})
    $scope.todos = $filter("filter")($scope.todos, {done:false});};

  $scope.addTodo = function () {
    entry = Todo.save({title:$scope.newTodo.title, 
importance:$scope.newTodo.importance, description:$scope.newTodo.description, 
done:false})
    $scope.todos.push(entry);
    $scope.newTodo.title = '';
    $scope.newTodo.importance = '';
    $scope.newTodo.description = '';
  };
}

What is happening is that rather than updating that object in the database, it 
is creating a brand new todo item and just giving it the attribute of :done => 
true. It makes sense because in thatclearCompleted function it looks like we 
are creating an object not updating an existing one.

How do I update the record in the database then?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to