Backbone.sync = (method, model, options) -> type = methodMap[method] params = type: type dataType: "json" params.url = getUrl(model) or urlError() unless options.url if not options.data and model and (method is 'create' or method is 'update') extra = options.extra data = model.toJSON() data = _.extend data, extra unless extra is undefined params.contentType = "application/json" params.data = JSON.stringify data if method is 'delete' param = $("meta[name= 'csrf-param']").attr 'content' token = $("meta[name= 'csrf-token']").attr 'content' data = authenticity_token: token params.contentType = 'application/json' params.data = JSON.stringify data emulate_json = Backbone.emulateJSON if emulate_json params.contentType = 'application/x-www-form-urlencoded' params.data = if params.data then model: params.data else {} if Backbone.emulateHTTP if type is 'PUT' or type is 'DELETE' params.data._method = type if emulate_json params.type = 'POST' params.beforeSend = (xhr) -> xhr.setRequestHeader "X-HTTP-Method-Override", type if params.type isnt 'GET' and not emulate_json params.processData = false params = _.extend params, options $.ajax params