6

Backbone Model.save doesn't wrap model state to nested object. Is it normal?

Typical scenario for Rails is something like this params[:product]. How could I achieve this?

Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197

1 Answers1

12

This was answered previously: Saving nested objects with Rails, backbone.js, and accepts_nested_attributes_for

I would suggest to override toJSON on the backbone model.

toJSON: function(){

  json = {car : this.attributes};
  return _.extend(json, {engine_attributes: this.get("engine").toJSON());

}

toJSON is called within the sync method just before sending data to the backend.

Community
  • 1
  • 1
Julien
  • 9,216
  • 4
  • 37
  • 38