javascript - CRUD's save method refers to wrong URL -


i need task.save go /users/:user_id/tasks seems refer wrong path , error:

no route matches [post] "/users/tasks" 

how can solve issue? in advance.

js

var app = angular.module('todolist', ['ngresource', 'xeditable']);    app.factory('task', [     '$resource', function($resource) {       return $resource('users/:user_id/tasks/');      }    ]);    app.controller('tasksctrl', [     '$scope', 'task', function($scope, task) {       $scope.addnewtask = function() {        var task = task.save($scope.newtask);        $scope.tasks.push(task);        $scope.newtask = {};      };    }   ]); 

you aren't telling resource :user_id path parameter from.

you either supply when call save

task.save({user_id: 'some value'}, $scope.newtask) 

or, if property part of $scope.newtask, eg $scope.newtask = {id: 'some id'}, declare in resource definition

return $resource('users/:user_id/tasks', {user_id: '@id'}) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -