I've got a backbone model that I'm trying to destroy, but no params are being sent with the request, so the server is returning a 'Delete 404 not found' error.
I'll admit my structure is a bit strange as I'm creating/destroying the items based on if they are in a list already or not.
var list_item = new MyApp.Models.ListItem({item_id: this.model.id, group_id: this.model.group_id}); if($(e.currentTarget).hasClass('add')){ list_item.save(list_item, { success: function(response){ this.model.attributes.addedtolist_id = response.id console.log(this.model); }, error: function(){ alert('could not save item'); } }); } else if($(e.currentTarget).hasClass('remove')) { list_item.id=this.model.addedtolist_id; list_item.attributes.id = this.model.addedtolist_id; console.log(list_item); list_item.destroy({ success: function(){ alert('delete'); }, error: function(){ alert('could not uncheck'); } }); }
the console output for list_item
before destroy is
_escapedAttributes: Object _previousAttributes: Object _setting: false attributes: Object id: 2 item_id: 66 group_id: 64 __proto__: Object cid: "c23" id: 2 __proto__: q
but when I look at the headers sent with the delete request, I don't have any params being sent.
-----------------------update params being sent, 404 still being returned --------------
as per Yaroslav's recommendation, I've added a 'header' to the destroy method, but my rails controller is still returning a DELETE 404 not found
error. I'm just trying to return the listitem to make sure i'm getting the right one before I destroy it.
My controller is
def destroy listitem = Listitem.find(params[:id]) return render :json => listitem end
id
? I don't see it in thenew ListItem
. And what does the URL look like for the DELETE request? – Gregnew ListItem
because that is when the listitem is being created, so it doesn't have an id yet. That is why I create the id before thedestroy
. The url isDELETE http://10.1.1.7:3000/list_items 404 (Not Found)
. I use the same url for index and create methods, which work no problem. – Urataurl
orurlRoot
inListItem
? – Gregfetch
andsave
which work fine. – Uratalist_item.url = 'list_items/'+list_item.id
, it worked. I thought the way it worked was to send the delete as a param. If you add your url bit as an answer I'll accept it. – Urata