I would not create a sub-URL unless you really have a good argument. Each resource can be identified by a resource name and identifier. The connection between objects is internal.
http://foo.com/a/:id.json http://foo.com/b/:id.json http://foo.com/c/:id.json
This means that many server calls to pull out nested objects are not really ideal. You better have a single resource that returns nested json
http:
For example, the data returned from my server looks like
{ "id": 372, "context": "office_work", "date_of_entry": "2011-7-05 15:22:00", "blood_glucose_measurement": 98, "food": { "exchanges": "98", "list": "burger fries" }, "exercise": { "duration": "28", "list": "running shopping" } }
Under the nodes are collected by the user controller, which takes individual db records and creates a data tree.
However, you have problems right now because backbone.js initially only supports flat structures. I made some changes to the underlying Backbone.Model to support a processing tree similar to structures.
I'll put it here if it can come in handy.
You can use it as
model = new RailsModel model.url = "/data" model.fetch() model.get('excercise/duration') model.set_field('excercise/duration', 25)
The last line will raise the event "change: excercise / duration"
source share