骨干和Rails嵌套路线

问题描述:

我在轨道定义了以下路线:

I have the following routes defined in rails:

resources :accounts do
  resources :transactions
end

这导致类似的网址:

/accounts/123/transactions/1

有一个简单的方法来此映射建立骨干模式?

Is there an easy way to map this to a backbone model set up?

原来骨干很容易通过在模型嵌套集合支持此如下:

Turns out backbone quite easily supports this by nesting a collection in a model as follows:

var Account = Backbone.Model.extend({

  initialize: function() {
    this.transactions = new TransactionsCollection;
    this.transactions.url = '/account/' + this.id + '/transactions';
    this.transactions.bind("reset", this.updateCounts);
  },
});

这实现正是我想要的。

您可以阅读更多关于它在这里:http://documentcloud.github.com/backbone/#FAQ-nested

You can read more about it here: http://documentcloud.github.com/backbone/#FAQ-nested