Alex Nikolsky
Alex Nikolsky

Reputation: 2169

Why isn't my function referring to a correct route?

My function is using update() method to update object's value. The problem is that it's referring to users/:user_id/tasks and I need users/:user_id/tasks/:id. Why is that so and how can I solve it?

var app = angular.module('Todolist', ['ngResource']);

  app.factory('Task', [
    '$resource', function($resource) {
      return $resource('/users/:user_id/tasks/:id', {user_id: '@user_id'}, {update: {method: 'PUT'}});
     }
   ]);

  app.controller('TasksCtrl', [
    '$scope', 'Task', function($scope, Task) {

      $scope.user = gon.current_user

      $scope.updateTitle = function(data, task) {
        Task.update({
          user_id: $scope.user.id,
          id: task.id,
          title: data
        });
      };
 }
]);

enter image description here

Upvotes: 1

Views: 49

Answers (1)

Satpal
Satpal

Reputation: 133403

You are not setting id parameter value when defining $resource

Use

return $resource('/users/:user_id/tasks/:id', {
    user_id: '@user_id',
    id: '@id'
}, {
    update: {
        method: 'PUT'
    }
});

Upvotes: 3

Related Questions