title: 404 Not Found error on ngResource delete in AngularJS & Rails
body: <p>I have an Account Controller in AngularJS for an Accounts page, and on this page Records are displayed related to that Account. </p>
  
  <p>The url of the page is based on the Acccount:</p>
  
  <pre><code>http://localhost:3000/#/accounts/16
  </code></pre>
  
  <p>In my accounts controller I retrieve the records:</p>
  
  <pre><code>            Account = $resource('/accounts/:accountId', {
                  accountId: "@id",
                  format: 'json'
              }, {
                  'save': {
                      method: 'PUT'
                  },
                  'create': {
                      method: 'POST'
                  }
              });
  
              var Record = $resource('/records/:recordId', {
                  recordId:'@id',
                  format: 'json'
              }, {
                  'save': {
                      method: 'PUT'
                  },
                  'create': {
                      method: 'POST'
                  },
                  'delete': {
                      method: 'DELETE'
                  }
              });
  
              if ($routeParams.accountId) {
                  Account.get({
                      accountId: $routeParams.accountId
                  }, (function(account) {
                      return $scope.account = account;
                  }), (function(httpResponse) {
                      $scope.account = null;
                      return flash.error = "There is no account with ID " + $routeParams.accountId;
                  }));
  
                  Record.query({
                      account_id: account_id
                  }, function(results) {
                      return $scope.records = results;
                  });
  
              } else {
                  $scope.account = {};
                  $scope.records = [];
              }
  </code></pre>
  
  <p>They are displayed on the Accounts page:</p>
  
  <pre><code>    &lt;tbody&gt;
          &lt;tr ng-repeat="record in records"&gt;
              &lt;td&gt;{{record.name}}&lt;/td&gt;
              &lt;td&gt;{{record.description}}&lt;/td&gt;
              &lt;td&gt;
                  &lt;button type="submit" ng-click="deleteRecord(record)"&gt;Delete&lt;/button&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  </code></pre>
  
  <p>The delete method:</p>
  
  <pre><code>            $scope.deleteRecord = function(record) {
  
                  record.$delete(function() {
                      return flash.success = "Record deleted successfully.";
                  });
  
                  var records = $scope.records;
  
                  for (var recordKey in records) {
                      if (records[recordKey]._id == record._id) {
                          $scope.records.splice(recordKey, 1);
                      }
                  }
                  return;
  
              };
  </code></pre>
  
  <p>My problem is when attempting to delete a Record I get the following error:</p>
  
  <pre><code>DELETE http://localhost:3000/records/2    [HTTP/1.1 404 Not Found  69ms]
  </code></pre>
  
  <p>The following output is displayed in the terminal when running rails server:</p>
  
  <pre><code>Started DELETE "/records/2?format=json" for 127.0.0.1 at 2015-06-15 21:18:04 -0400
  Processing by RecordsController#destroy as JSON
    Parameters: {"id"=&gt;"2"}
    Record Load (4.5ms)  SELECT  "records".* FROM "records" WHERE "records"."id" = $1 LIMIT 1  [["id", 2]]
    Rendered text template (0.0ms)
  Completed 404 Not Found in 12ms (Views: 4.7ms | ActiveRecord: 4.5ms)
  </code></pre>
  
  <p>How can I delete records when I am not on the current page for that model? </p>
  
  <p>Deleting items this way works when I am deleting the specific model of the page I am on (i.e. Deleting an Account from the Accounts page).</p>
  
  <p>My controller action for reference:</p>
  
  <pre><code>  def destroy
      record = Record.find(params[:id])
      record.destroy!
      head :no_content
    end
  </code></pre>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks!</p>