I'm using revision 12 of Ember Data.
I've got a simple method on an ArrayController
that tries to delete a single record, and is called from an action in a template:
deleteFact: function(fact) {
self=this;
window.App.confirm(Em.I18n.t('Delete fact?'), {
yes: function() {
fact.deleteRecord();
fact.store.commit();
}
});
}
This always works with the first record deleted, and the list shows the record disappears. I'm using Rails, and the server processes the DELETE
and returns a JSON empty object and status 200
. If I delete another record any time after that first delete I always get an internal exception thrown immediately:
Uncaught Error: Attempted to handle event
deleteRecordon <App.Fact:ember402:31> while in state rootState.deleted.saved. Called with undefined
What's the right way to delete a record. I've searched Google and can't find any answers, and the source code and tests for ember data look like this is all that has to be done.
Template:
{{#each fact in content}}
<tr>
<td>{{fact.title}}</td>
<td>{{fact.body}}</td>
<td>{{#linkTo 'facts.show' fact}}View{{/linkTo}} | <a {{ action 'deleteFact' fact}} class="button small deny delete-button">Delete</a>[{{fact.id}}]({{fact.stateManager.currentState.path}})</td>
</tr>
{{else}}
<tr>
<td colspan='4'>No facts registered at present.</td>
</tr>
{{/each}}
Template Output:
Title Facts Actions
asdfsd asdfsadf View | Delete[46](rootState.loaded.saved)
asdfsd asdfsadf View | Delete[47](rootState.loaded.saved)
asdfsd asdfsadf View | Delete[48](rootState.loaded.saved)
Output in Console:
Clicking delete on record with Fact Id 46 logs to console from the yes function that id 46 was passed. Record disappears from list displayed by template, leaving two records with id 47, and 48. Clicking delete for record 47 shows in log that record id 46 was passed again.