0

I am trying to remove a view once the user clicks on something and then also delete the model thats associated with that view. I am successfully remove the model however this.model.destroy method doesnt send any server requests ?

this is how my code looks like:

PostsApp.Models.Post = Backbone.Model.extend({
    url : '/tweet',
    defaults:{
        name: '',
        adress: '',
        pictureUrl: '',
        postListing: '',
        comments: ''
    }
});

PostsApp.Collections.Posts = Backbone.Collection.extend({
    model: PostsApp.Models.Post,
    url: '/tweet'
});

PostsApp.Views.Post = Backbone.View.extend({
    template: _.template($('#post-template').html()),

    events: {
        'click img': 'removeit'
    },

    removeit: function(){
        this.remove();
        this.model.destroy();
    },

    render: function(){
        this.$el.html(this.template(this.model.toJSON()));
    }

});

I am using express on the server side and how am I supposed to handle the HTTP delete request in the server side? But it seems like no request is being sent?

edit:

So I made a little progress changed my model to:

PostsApp.Models.Post = Backbone.Model.extend({
    urlRoot : '/tweet',
    idAttribute: '_id',
    defaults:{
        name: '',
        adress: '',
        pictureUrl: '',
        postListing: '',
        comments: ''
    },
    kill: function(){
        this.destroy({success: function(model, response) {
            console.log("sucess");
    }});
    }
});

and my server side router is set like this to handle the request :

app.delete('/tweet/:id'), function(req,res){
};

Now a delete request is being sent like: DELETE /tweet/51b2548ba8568587ea000002 but I am getting a 404 error like this: DELETE localhost:3000/tweet/51b2548ba8568587ea000002 404 (Not Found)

s_curry_s
  • 3,332
  • 9
  • 32
  • 47

1 Answers1

0
app.delete('/tweet/:id'), function(req,res){
};

my parenthesis were placed wrong here.. wow , so it should have been:

app.delete('/tweet/:id', function(req,res){
});

weird that express didnt throw any errors..

s_curry_s
  • 3,332
  • 9
  • 32
  • 47