4

I have a quick question. In angular js where (like which object) does the '@id' come from in the following piece of code from a rails app?

var User = $resource("/users/:id", {id: '@id'});

I know it sets the default id.

Thanks

GTDev
  • 5,488
  • 9
  • 49
  • 84

1 Answers1

7

From the AngularJs documentation:

"If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object (useful for non-GET operations)."

This means that when calling a non-GET operation, like POST, you can pass the id as one of the fields of the data object you include in the call.

remigio
  • 4,101
  • 1
  • 26
  • 28
  • So what is the data object in the case of a rails app? – GTDev Feb 25 '13 at 21:21
  • 1
    var User = $resource("/users/:userId", {userId: '@id'}); if you have a user with an id ( var user = new User({id : 1}) ) then if you call user.$save() it will send a post request with this url /users/1 (userId take the value of the id property) – Olivier Boissé May 18 '16 at 13:19