Skip to content

Commit 1a8fbe0

Browse files
committed
Fix addRestangularMethodFunction to handle post/put/delete properly
1 parent 00ea6c7 commit 1a8fbe0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/restangular.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,13 +1243,10 @@ module.provider('Restangular', function() {
12431243

12441244
function addRestangularMethodFunction(name, operation, path, defaultParams, defaultHeaders, defaultElem) {
12451245
var newRestangularObject,
1246-
createdFunction;
1246+
createdFunction,
1247+
urlBuilder = operation === 'getList' ? 'all' : 'one';
12471248

1248-
if (operation === 'getList') {
1249-
newRestangularObject = this.all(path);
1250-
} else {
1251-
newRestangularObject = this.one(path);
1252-
}
1249+
newRestangularObject = this[urlBuilder](path);
12531250

12541251
createdFunction = function(params, headers, elem) {
12551252
var params, headers, elem;
@@ -1258,7 +1255,15 @@ module.provider('Restangular', function() {
12581255
headers = _.defaults(headers, defaultHeaders);
12591256
elem = _.defaults(elem, defaultElem);
12601257

1261-
return newRestangularObject[operation](params, headers, elem);
1258+
return newRestangularObject.customOperation(
1259+
// umm, so the documentation specifies delete is one of the operations
1260+
// that can be pased to customOperation, but it totally means remove?
1261+
operation === 'delete' ? 'remove' : operation,
1262+
'',
1263+
params,
1264+
headers,
1265+
elem
1266+
);
12621267
};
12631268

12641269
if (config.isSafe(operation)) {

0 commit comments

Comments
 (0)