Reputation: 1765
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
Upvotes: 5
Views: 4874
Reputation: 146064
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.
Upvotes: 17
Reputation: 11538
You can pass it when calling destroy
.
this.model.destroy( { url: "your-custom-url/" } );
Upvotes: 7