documentcloud/backbone — pull request #781 by dima-exe (2011-12-12 20:36:12+00:00)
Title: Rails like url templates in Backbone.Model.urlRoot and Backbone.Collection.url

Example in model:

var Comment = Backbone.Model.extend({
urlRoot: ["/comments", "/videos/:video_id/comments", "/albums/:album_id/videos/:video_id/comments"]
})

// url() -> /comments/1
new Comment()
// url() -> /videos/2/comments/1
new Comment(..., {params:{video_id:2}})
// url() -> /albums/3/videos/2/comments/1
new Comment(..., {params:{video_id:2, album_id:3}}) or
new Comment({id:1,video_id:2, album_id:3})

Example in Collection:

var Comments = Backbone.Collection.extend({
url: ["/comments", "/videos/:video_id/comments", "/albums/:album_id/videos/:video_id/comments"]
})

// url -> /comments/1
new Comments()
// url -> /videos/2/comments/1
new Comments(..., {params:{video_id:2}})
// url -> /albums/3/videos/2/comments/1
new Comments(..., {params:{video_id:2, album_id:3}})