Question

Iam using Restangular on the clientside with _id as Id field. Sadly Restangular generates wrong URLs, maybe you could say me where the error is?

Restangular.all('/users').one(id).get().then(functon(results) {
    $scope.data = results;
})

After the user edited the data:

$scope.save = function() {
     $scope.data.put().then(...);
};

This very simple sample generates the following URL with the id twice. I have no idea what went wrong. :(

PUT /users/537283783b17a7fab6e49f66/537283783b17a7fab6e49f66

Was it helpful?

Solution

Solved it by changing the Request workflow of Restangular.

I don't now why, but this approad does not work:

Restangular.all('/users').one(id).get() ... result.put();

But this does:

Restangular.one('/users/',id).get() ... result.put();

Also it is important to tell Restangular that you were using _id instead of id:

angular.module('App').config(function(RestangularProvider, AppSettings) {
  RestangularProvider.setRestangularFields({id: "_id"});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top