Q:

Backbone Model Structure

I'm making a Grocery list app, which is very similar with the todo list. I have several years of Rails dev experience, but am having trouble figuring out from all the examples what to put into a collection, and what to make a model.
I mocked up the app with Sinatra and Redis as the backend. My goal is to make Sinatra just the simple API and have backbone manage all the view.
Right now, a Grocery list is just a complex ID, which has a Set of string items. So something like:
/lists/asdfasdf34asdf => ["eggs", "bacon", "milk"]

Moving to backbone, would I make the model an "Item" and then the collection would be the "List", or would it be something else?
I guess my routes aren't classic Rest so maybe that's why i'm having trouble sorting out what to do where.

A:

If there's only one grocery list, a Collection of item Models is probably appropriate. Backbone isn't too prescriptive about how things are organized, but you will definitely want to set the url property of each model/collection in a logical fashion. You might do something like this:
var app = {
  item: Backbone.Model.extend({
    // define an item model to go in the itemCollection
  }),
  itemCollection: Backbone.Collection.extend({
    initialize: function (key) {
      this.key = key;
    },
    model: app.item,
    url: function () {
      return 'lists/' + this.key + '/items/'
    }
  })
}

and then instantiate each version of the application along these lines:
var userListKey = 'foobar',
    userCollection = new app.itemCollection(foobar);

// proceed with app. Requests for userCollection will now be
// directed to /lists/foobar/items

There are many other ways to do this, but hopefully this is a start. 

