title: Extend AngularJS $resource to map to Rails RESTful Routes (particularly $save to create AND update)
body: <p>I'd like to map the default AngularJS $resource actions:</p>
  
  <pre><code>  'get':    {method:'GET'}
    'save':   {method:'POST'}
    'query':  {method:'GET', isArray:true}
    'remove': {method:'DELETE'}
    'delete': {method:'DELETE'}
  </code></pre>
  
  <p>to these 5 Rails RESTful routes:</p>
  
  <pre><code>  'show':   {method:'GET'}                 -&gt; get
    'create': {method:'POST'}                -&gt; save
    'update': {method:'PUT'}                 -&gt; save
    'index':  {method:'GET', isArray:true}   -&gt; query
    'delete': {method:'DELETE'}              -&gt; remove or delete
  </code></pre>
  
  <p>Everything maps well except for <code>save</code>. It works on <code>create</code> as a <code>POST</code> request. But I'd like to change it to a <code>PUT</code> request when I'm saving a resource that has an <code>id != null</code></p>
  
  <pre><code># This factory needs a smarter $save() method
  myServices.factory 'Message', ['$resource', ($resource) -&gt;
      Message = $resource "api/users/:user_id/messages/:id",
          user_id: '@user_id'
          id: '@id'
      ,
          # update should not be needed
          update:
              method: 'PUT'
  
      Message
  ]
  
  
  myApp.controller "UsersShowCtrl", ["$scope", "$routeParams", "User", "Message", ($scope, $routeParams, User, Message) -&gt;
      $scope.user = User.get({id: $routeParams.user_id})
      $scope.myMessage = new Message {user_id: $routeParams.user_id}
  
      $scope.submitMyMessage = -&gt;
          # This should just be:
          # $scope.myMessage.$save()
          # rather than:
          unless $scope.myMessage.id?
              $scope.myMessage.$save()
          else
              $scope.myMessage.$update()
  
  ]
  </code></pre>
  
  <p>I would ultimately like to modify the the submitted params as well so that I can namespace them to the default rails nested params i.e. <code>params[:message]</code> rather than attaching them directly to the root <code>params</code> string, but first I need to know how best to modify the the $resource.</p>