Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS removing data from postdata
    primarykey
    data
    text
    <p>I'm following the example from mightygio (<a href="http://mightygio.com/2013/05/integrating-rails-and-angularjs-part-3-rest-and-angular-resource" rel="nofollow">http://mightygio.com/2013/05/integrating-rails-and-angularjs-part-3-rest-and-angular-resource</a>) and would like to simplify the postData when updating.</p> <p>Currently I have this</p> <pre><code> $scope.update = -&gt; Letter.update id: $stateParams['id'] , letter: subject: $scope.letter.subject body: $scope.letter.body # success , (response) -&gt; $location.path "/letters" # failure , (response) -&gt; </code></pre> <p>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:</p> <pre><code> $scope.update = -&gt; Letter.update id: $stateParams['id'] , letter: $scope.letter # success , (response) -&gt; $location.path "/letters" # failure , (response) -&gt; </code></pre> <p>The problem I have is I cannot pass certain attributes to my backend when updating these are created_at, id &amp; updated_at keys. </p> <p>How could I remove these keys before sending my JSON to the server?</p> <p><strong>UPDATE</strong></p> <p>I suppose I could use something like this, but is there a better way?</p> <pre><code> $scope.update = -&gt; letter = {} # Strip out id, created_at &amp; updated_at angular.forEach($scope.letter, (value,key) -&gt; if(key!='id' &amp;&amp; key!='created_at' &amp;&amp; key!='updated_at') letter[key]=value ,letter) Letter.update id: $stateParams['id'] , letter: letter # success , (response) -&gt; $location.path "/letters" # failure , (response) -&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload