I'm following the example from mightygio (http://mightygio.com/2013/05/integrating-rails-and-angularjs-part-3-rest-and-angular-resource) and would like to simplify the postData when updating.
Currently I have this
$scope.update = ->
Letter.update
id: $stateParams['id']
,
letter:
subject: $scope.letter.subject
body: $scope.letter.body
# success
, (response) ->
$location.path "/letters"
# failure
, (response) ->
When I have a large form with lots of data this gets rather long and hard to maintain. It would be nicer if I could just pass the $scope.letter like so:
$scope.update = ->
Letter.update
id: $stateParams['id']
,
letter: $scope.letter
# success
, (response) ->
$location.path "/letters"
# failure
, (response) ->
The problem I have is I cannot pass certain attributes to my backend when updating these are created_at, id & updated_at keys.
How could I remove these keys before sending my JSON to the server?
UPDATE
I suppose I could use something like this, but is there a better way?
$scope.update = ->
letter = {}
# Strip out id, created_at & updated_at
angular.forEach($scope.letter, (value,key) ->
if(key!='id' && key!='created_at' && key!='updated_at')
letter[key]=value
,letter)
Letter.update
id: $stateParams['id']
,
letter: letter
# success
, (response) ->
$location.path "/letters"
# failure
, (response) ->