Skip to content

Instantly share code, notes, and snippets.

@gouthamvel
Created April 17, 2012 18:39
Show Gist options
  • Save gouthamvel/2408096 to your computer and use it in GitHub Desktop.
Save gouthamvel/2408096 to your computer and use it in GitHub Desktop.
class Deliveryguy.Routers.PostsRouter extends Backbone.Router
initialize: (options) ->
@posts = new Deliveryguy.Collections.PostsCollection()
@posts.reset options.posts
routes:
"/new" : "newPost"
"/index" : "index"
"/:id/edit" : "edit"
"/:id" : "show"
".*" : "index"
newPost: ->
@view = new Deliveryguy.Views.Posts.NewView(collection: @posts)
$("#posts").html(@view.render().el)
index: ->
@view = new Deliveryguy.Views.Posts.IndexView(posts: @posts)
$("#posts").html(@view.render().el)
show: (id) ->
post = @posts.get(id)
@view = new Deliveryguy.Views.Posts.ShowView(model: post)
$("#posts").html(@view.render().el)
edit: (id) ->
post = @posts.get(id)
@view = new Deliveryguy.Views.Posts.EditView(model: post)
$("#posts").html(@view.render().el)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment