Question

i cannot delete record using RESTAdapter.

Model:

Blog.Post = DS.Model.extend({
title:DS.attr('string'),
body:DS.attr('string'),
date:DS.attr('date')
});

ApplicationAdapter:

Blog.ApplicationAdapter = DS.RESTAdapter.extend({
host:'http://localhost:8080',
namespace: 'api',
serializer: Blog.ApplicationSerializer
});

I have a button with action:

<button {{action deletePost this target="controller"}}>Delete post</button>

And controller:

Blog.PostController = Ember.ObjectController.extend({
    actions:{
        deletePost: function () {
            var post = this.get('model');
            post.deleteRecord();
            post.save();
        }
    }
});

In action i get this model:

Object {date: Thu May 15 2014 11:38:49 GMT+0400 (VOLT),
body: "131313313131311313133",
title: "131313313131311313133",
__v: 0, id: "53746f09c7cc34da0d000001"…}
__ember1400142799882_meta: Meta
__v:
0 body: (...)
get body: function ()
{ set body: function (value)
{ date: (...) get date: function ()
{ set date: function (value)
{ id: (...) get id: function ()
{ set id: function (value)
{ title: (...) get title: function ()
{ set title: function (value) {
__proto__: Object

And next exception: Uncaught TypeError: undefined is not a function This exception throws when i call post.deleteRecord()

Was it helpful?

Solution

A possible solution might be similar to this one. You could define the deletePost action in the Route object and then access the model by this.currentModel.

Template:

<button {{action deletePost this}}>Delete post</button>

Route:

Blog.PostRoute = Ember.Route.extend({

  actions:{
      deletePost: function () {
        var post = this.currentModel;
        post.deleteRecord();
        post.save();
      }
  }

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top