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
Post a Comment