Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to override the url while calling model.destroy in backbone

Rigt now i am calling model.destroy(), a DELETE request to the server side

I want to override the url call while doing destroy, I wont be able to change the urlRoot.

Is there any way ?

Thanks, Prats

like image 820
Prats Avatar asked Feb 26 '13 15:02

Prats


2 Answers

var MyModel = Backbone.Model.extend({
    destroy: function (options) {
        var opts = _.extend({url: '/destroy/' + this.id}, options || {});
        return Backbone.Model.prototype.destroy.call(this, opts);
    }
)};

All AJAX-based interactions are ultimately handled by Backbone.sync which takes an options object where the URL can be provided if backbone's default URL scheme doesn't work for your server.

like image 73
Peter Lyons Avatar answered Oct 02 '22 14:10

Peter Lyons


You can pass it when calling destroy.

this.model.destroy( { url: "your-custom-url/" } );

like image 32
neebz Avatar answered Oct 02 '22 14:10

neebz