I have a post which has many comments, and I want to display the comments on the post page. This is a Rails 3 application and I have my comments’ URLs nested in the post’s URL, so it basically looks like /post/1/comments.
The problem is, I’m not really sure how should I create a backbone collection for this situation. Should I just pass the post_id to the javascript form the server and then do something like
var Comments = Backbone.Collection.extend({
model: Comment,
url: '/post/' + idFromSomewhereElse + '/comments'
});
or is there a better way to handle this? How should I handle this in case of multiple nesting, where I could have something like /forums/1/topics/3/replies.
One idea could be to delegate the root of the
Comments.urlto thePostparent model:I think this idea can scale also for more complicate relations like
/forums/1/topics/3/replies. You just have to take care of mantain the relation from every Collection to its parent.