Skip to content

Instantly share code, notes, and snippets.

@merqlove
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merqlove/ccdc89cd7e54266e82c3 to your computer and use it in GitHub Desktop.
Save merqlove/ccdc89cd7e54266e82c3 to your computer and use it in GitHub Desktop.
Angular $resource experience with Rails based API
# Create service for our factories. Don't blow .json extension. This is easiest path to get JSON request in AUTO mode.
angular.module("identityService", ["ngResource"])
.factory 'Identity', ($resource) ->
$resource '/api/v1/identities/:id.json',
{ id:'@id' }
# Added update via PUT
@identities.config ($resourceProvider) ->
$resourceProvider.defaults.actions.update = { method: 'PUT' }
# Run our test
@identities.controller 'RestaurantIndexCtrl', ($scope, Identity) ->
data = {
identity: {
user_id: 55
provider: "vkontakte"
}
}
Identity.save(data)
Identity.update id:1, identity: {user_id:444}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment