Reputation: 2052
I have a pretty basic factory:
app.factory('Person', function($resource) {
return $resource(API_ROUTE+'/people/:id.json', {
id: "@id"
}, {
update: {
method: "PUT"
}
});
});
It performs a get
request with the specified URL as expected, but when I tried to do an update, it goes to /people.json
instead of /people/:id.json
.
Person.get({
id: personId
}, function(person) {
return $scope.person = person;
});
$scope.person.$update()
The response I get from the server logs:
Started PUT "/hr/angular/people.json" for 128.104.86.165 at 2015-04-14 14:12:30 -0500
ActionController::RoutingError (No route matches [PUT] "/angular/people.json"):
I tried a different way of doing the update command but got the same response.
Person.update($scope.person, function(person) {
console.log($person);
});
If I hardcode an id into the resource path, like $resource(API_ROUTE+'/people/1234.json')
, I'm able to do all the expected actions on that individual, including update. I don't see what I'm missing that would allow the get
method of a resource use the proper path but not an update.
Upvotes: 0
Views: 268
Reputation: 5116
You need to pass your id Into the update method don't you?
$scope.person.$update({ id: 1 }, function(response) {
//
});
Upvotes: 1