Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js .destroy Passing Additional Params?

Tags:

backbone.js

When .destroy'ing a Model, I need to pass an additional parameter to my Rails app. I've read a few posts on how to do this, however my Rails app still isn't recognizing it. Any suggestions? The parameter is program_id

var thisDeal = new WhiteDeals.Models.EditorDeal({ id: dealID }); 
thisDeal.destroy({headers: { program_id: dealProgram.id } })

Here's the server log. As you can see, the program_id parameter isn't showing up:

Started DELETE "/editor_deals/46" for 127.0.0.1 at 2013-04-13 13:26:32 -0700
Processing by DashboardController#deal_destroy as JSON
Parameters: {"id"=>"46"}
like image 474
ac360 Avatar asked Apr 13 '13 20:04

ac360


1 Answers

The object what you pass as a parameter to destroy will eventually end up as the settings parameter to a jQuery.ajax call.

So if you need to send additional data you need to use the data proeprty:

var thisDeal = new WhiteDeals.Models.EditorDeal({ id: dealID }); 
thisDeal.destroy({data: { program_id: dealProgram.id }, processData: true})
like image 168
nemesv Avatar answered Dec 05 '22 05:12

nemesv