codebrew / backbone-rails

Easily use backbone.js with rails 3.1
MIT License
1.62k stars 255 forks source link

Fix PATCH support in sync function #178

Open nneufeld opened 9 years ago

nneufeld commented 9 years ago

As per the backbone documentation for model.save(http://backbonejs.org/#Model-save)

If instead, you'd only like the changed attributes to be sent to the server, call model.save(attrs, {patch: true}). You'll get an HTTP PATCH request to the server with just the passed-in attributes.

This currently doesn't work when including backbone_rails_sync, as the data option was always being set to model.toJSON, which returns all the model's attributes, when in fact it should be set to options.attrs if it's present, which contains only the attributes that have been changed when using the patch option.