(Rails 3 + backbone 0.53)
I am fetching data from my API on “/payments” url and it returns different kinds of payment data.
So the user can for example delete, let’s say a credit-card entry and it is synced backed to the server on
"/credit_cards".
The problem is that if I use Backbone.Sync with the syntax
Backbone.Sync('delete', @options.credit_cards.get('id'))
it gives me an “A “url” property or function must be specified” error.
This makes sense as the model e.g.:
@options.credit_cards.get('id')
does not exist in this case because credit_cards doesn’t store any data. I just wanna do a standard DELETE with Backbone.sync á la
"/credit_cards/:id"
but just by specifying the id (which I receive from /payments) not the model (but the model/collection has the url…)
So my question is: 1.)
is there a way in backbone to use backbone.sync without actually storing data in a collection/model, more like a simple ajax request with jQuery.
Example:
Backbone.Sync('delete', "specify_a_url_here_with/#{id}"))
instead of using Backbone.Sync & $.ajax requests mixed.
2.) does that make sense at all or is there a better alternative.
Thanks a lot! I really love SO! Hope the question isn’t to weird. Phil
You can pass “url” and “data” to Backbone.Sync in “options”.
Backbone.sync(method, model, options) returns a $.ajax(params) where params.url and params.data reflect your model unless you exlicitly pass them in options.
So
should work.