I was stuck with AngularJS - Rails capability. ngResource sends POST requests both on create and update. I found solutions for this problem for ngResource, but I would like to solve it on Rails side. I think there are no any conflicts 'course update and create performs on different URIs
Asked
Active
Viewed 242 times
2 Answers
1
You can change Rails resource to accept post method for update action.
However, I do not recommend this way because RESTful way of update has better to be PUT
method, not POST
As you said, you found a soultion to send PUT request on ngResource. I highly recommend that way.
From http://blog.safaribooksonline.com/2013/05/16/angularjs-ngresource-tips-and-tricks/, ngResource does not support PUT out of the box, but it is extremely easy to implement:
var res = $resource('/your/url/:id', {foo: 'bar'}, {'put': {method:
'PUT', params: {foo: 'baz'}, isArray: false}});
Here is another discussion about it, and we better not to use POST
for update again.

Community
- 1
- 1

allenhwkim
- 27,270
- 18
- 89
- 122
-
The problem is ngResource does not distinguish between create and update actions while $save is called. It just appends ID to uri if it exists in object. Because of this I need to overwrite $save method in resource instance prototype. – atomAltera Sep 18 '13 at 07:44
0
Did you try overriding it in your routes.rb
like this? I never tried it with the standard actions, but it might just work for you:
resources :users do
post 'update', :on => :member
end

Rajesh Kolappakam
- 2,095
- 14
- 12
-
If it conflicts with the other update method, you might add `resources :users, :except => :update do` – Mark Swardstrom Sep 17 '13 at 04:26