Reputation: 2169
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
});
};
}
]);
Upvotes: 1
Views: 49
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