Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I'm currently stuck on an update list problem. I use Rails and AngularJS.

On JS side, I plugged jQueryUI for sortable feature with Angular $resource feature to read, update (and in second step, delete and create) a text block that is ordered.

eg.

  • "1 - lorem ipsum"

  • "2 - second position lorem ipsum"

  • "3 - the third position"


in AngularJS controller I have this :

 function DndCtrl($scope, $resource) { var Feed = $resource('/users/'+ userId +'/test/:id', {id: '@id'}, {'update': {method:"PUT", isArray:true}}); $scope.tests = Feed.query(function() { $scope.updateSortable = { // jQueryUI methods update: function(e, ui) { // trigger after user ends dropping item for (var i=0; i<$scope.tests.length; i++) { var t = $scope.tests[i]; t.position = i+1; t.$update(); } }, placeholder: "t-hightlight", axis: 'y' }; }); } // end DnD 

OUTPUT after sorted element :

 PUT http://demo.mytest.dev/users/1/test/1 401 (Unauthorized) 

and in the server log :

 warning can't verify csrf 

So I found on this topic : Rails CSRF Protection + Angular.js: protect_from_forgery makes me to log out on POSTRails CSRF Protection + Angular.js: protect_from_forgery makes me to log out on POST the answer from HuangYuHei and tried it.

The console OUTPUT then :

 GET http://demo.mytest.dev/users/1/test 404 (Not Found) 

And on server log :

 Test Load (1.9ms) SELECT "tests".* FROM "tests" WHERE "tests"."id" = 2 LIMIT 1 Unpermitted parameters: id 

I tested directly the request in the rails console and it returned well the entry.

What I'm I doing wrong ? Did I miss something on Rails config part ? or on Angular part ?

I'm currently stuck on an update list problem. I use Rails and AngularJS.

On JS side, I plugged jQueryUI for sortable feature with Angular $resource feature to read, update (and in second step, delete and create) a text block that is ordered.

eg.

  • "1 - lorem ipsum"

  • "2 - second position lorem ipsum"

  • "3 - the third position"


in AngularJS controller I have this :

 function DndCtrl($scope, $resource) { var Feed = $resource('/users/'+ userId +'/test/:id', {id: '@id'}, {'update': {method:"PUT", isArray:true}}); $scope.tests = Feed.query(function() { $scope.updateSortable = { // jQueryUI methods update: function(e, ui) { // trigger after user ends dropping item for (var i=0; i<$scope.tests.length; i++) { var t = $scope.tests[i]; t.position = i+1; t.$update(); } }, placeholder: "t-hightlight", axis: 'y' }; }); } // end DnD 

OUTPUT after sorted element :

 PUT http://demo.mytest.dev/users/1/test/1 401 (Unauthorized) 

and in the server log :

 warning can't verify csrf 

So I found on this topic : Rails CSRF Protection + Angular.js: protect_from_forgery makes me to log out on POST the answer from HuangYuHei and tried it.

The console OUTPUT then :

 GET http://demo.mytest.dev/users/1/test 404 (Not Found) 

And on server log :

 Test Load (1.9ms) SELECT "tests".* FROM "tests" WHERE "tests"."id" = 2 LIMIT 1 Unpermitted parameters: id 

I tested directly the request in the rails console and it returned well the entry.

What I'm I doing wrong ? Did I miss something on Rails config part ? or on Angular part ?

I'm currently stuck on an update list problem. I use Rails and AngularJS.

On JS side, I plugged jQueryUI for sortable feature with Angular $resource feature to read, update (and in second step, delete and create) a text block that is ordered.

eg.

  • "1 - lorem ipsum"

  • "2 - second position lorem ipsum"

  • "3 - the third position"


in AngularJS controller I have this :

 function DndCtrl($scope, $resource) { var Feed = $resource('/users/'+ userId +'/test/:id', {id: '@id'}, {'update': {method:"PUT", isArray:true}}); $scope.tests = Feed.query(function() { $scope.updateSortable = { // jQueryUI methods update: function(e, ui) { // trigger after user ends dropping item for (var i=0; i<$scope.tests.length; i++) { var t = $scope.tests[i]; t.position = i+1; t.$update(); } }, placeholder: "t-hightlight", axis: 'y' }; }); } // end DnD 

OUTPUT after sorted element :

 PUT http://demo.mytest.dev/users/1/test/1 401 (Unauthorized) 

and in the server log :

 warning can't verify csrf 

So I found on this topic : Rails CSRF Protection + Angular.js: protect_from_forgery makes me to log out on POST the answer from HuangYuHei and tried it.

The console OUTPUT then :

 GET http://demo.mytest.dev/users/1/test 404 (Not Found) 

And on server log :

 Test Load (1.9ms) SELECT "tests".* FROM "tests" WHERE "tests"."id" = 2 LIMIT 1 Unpermitted parameters: id 

I tested directly the request in the rails console and it returned well the entry.

What I'm I doing wrong ? Did I miss something on Rails config part ? or on Angular part ?

Source Link
user1713964
  • 1.3k
  • 2
  • 15
  • 26

Angular $resource query gets a 401 on PUT when no CSRF is defined and a 404 on GET when CSRF is defined :/

I'm currently stuck on an update list problem. I use Rails and AngularJS.

On JS side, I plugged jQueryUI for sortable feature with Angular $resource feature to read, update (and in second step, delete and create) a text block that is ordered.

eg.

  • "1 - lorem ipsum"

  • "2 - second position lorem ipsum"

  • "3 - the third position"


in AngularJS controller I have this :

 function DndCtrl($scope, $resource) { var Feed = $resource('/users/'+ userId +'/test/:id', {id: '@id'}, {'update': {method:"PUT", isArray:true}}); $scope.tests = Feed.query(function() { $scope.updateSortable = { // jQueryUI methods update: function(e, ui) { // trigger after user ends dropping item for (var i=0; i<$scope.tests.length; i++) { var t = $scope.tests[i]; t.position = i+1; t.$update(); } }, placeholder: "t-hightlight", axis: 'y' }; }); } // end DnD 

OUTPUT after sorted element :

 PUT http://demo.mytest.dev/users/1/test/1 401 (Unauthorized) 

and in the server log :

 warning can't verify csrf 

So I found on this topic : Rails CSRF Protection + Angular.js: protect_from_forgery makes me to log out on POST the answer from HuangYuHei and tried it.

The console OUTPUT then :

 GET http://demo.mytest.dev/users/1/test 404 (Not Found) 

And on server log :

 Test Load (1.9ms) SELECT "tests".* FROM "tests" WHERE "tests"."id" = 2 LIMIT 1 Unpermitted parameters: id 

I tested directly the request in the rails console and it returned well the entry.

What I'm I doing wrong ? Did I miss something on Rails config part ? or on Angular part ?