Make Restangular .remove() work with Rails Shallow Routes


Say, I have nested resources as follows,

shallow do
  resources :aalu do
    resources :pyaj

Using restangular I get the resources as required using the following Restangular call

all_pyaj ='aalu', $stateParams.aaluId).all('pyaj').getList();

pyaj is an element of the all_pyaj array, I get it using ng-repeat.

Now, When I want to remove the resource using Restangular using remove() method,
the pyaj.remove() makes a DELETE call to /aalu/:aalu_id/pyaj/:pyaj_id

I want it to make a DELETE call to /pyaj/:pyaj_id and remove the resrouce form the angular $scope too.

I can achieve this by the following way,'pyaj',
   function (response) { /* Problem: Delete this pyaj from $scope */ }

Can I make Restangular make a DELETE call to /pyaj/:pyaj_id and remove the resource form the angular $scope too?

How Restangular works with shallow routes?


You should configure Restangular with RestangularProvider.setParentless(['pyaj']); to tell it that any pyaj object should be “shallow”. See

Answered By – Meekohi

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.