Jay Claiton
Jay Claiton

Reputation: 437

Ember.js deleteRecord() in Controller not working

First I am using ember.js 1.0.0, ember-data 1.0.0 b3 with the DS.RESTAdapter.

Creating works fine so far, but if I try to delete a record (got it straight from the Getting Started) I receive the following Error Message:

Uncaught TypeError: Object [object Object] has no method 'deleteRecord'

This is my template:

   {{#each}}
   {{#link-to "role" this classBinding="isLoading:is-loading" tag="tr" }}
        <td>{{ name }}</td>
        <td>{{ role }}</td>
        <td><button {{ action "deleteRoleAction" this}}>[x]</button></td>
   {{/link-to}}
   {{/each}}

and this is the action (in the controller)

this.get('model').deleteRecord()

Any help appreciated.

Upvotes: 1

Views: 1219

Answers (1)

Nick Ragaz
Nick Ragaz

Reputation: 1352

Without knowing how your controller's model property was assigned, it's hard to say why that object wouldn't respond to deleteRecord. But it looks like what you're doing is iterating over the controller's content (presumably, a collection) and then passing the individual models to the action ({{action "deleteRoleAction" this}}). So you probably want your action to look like this:

deleteRoleAction: function(role) {
  role.deleteRecord();
}

Note that deleteRecord by itself only sets the deleted flag on the model; if you actually want to save that delete to your server, you need to call role.save(); too. (There is also a new destroyRecord method in 1.0.0.b4 that does both.)

Upvotes: 2

Related Questions