Sha256: 71475bb6b71083feda66f26f1023250eba5758af2813a3bce61ea51354f55a65

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

class <%= router_namespace %>Router extends Backbone.Router
  initialize: (options) ->
    @<%= plural_name %> = new <%= collection_namespace %>Collection()
    @<%= plural_name %>.reset options.<%= plural_name %>

  routes:
    "/new": "new<%= class_name %>"
    "/index": "index"
    "/:id/edit": "edit"
    "/:id": "show"
    ".*": "index"

  new<%= class_name %>: ->
    @view = new <%= "#{view_namespace}.NewView(collection: @#{plural_name})" %>
    $("#<%= plural_name %>").html(@view.render().el)

  index: ->
    @view = new <%= "#{view_namespace}.IndexView(#{plural_name}: @#{plural_name})" %>
    $("#<%= plural_name %>").html(@view.render().el)

  show: (id) ->
    <%= singular_name %> = @<%= plural_name %>.get(id)
    
    @view = new <%= "#{view_namespace}.ShowView(model: #{singular_name})" %>
    $("#<%= plural_name %>").html(@view.render().el)
    
  edit: (id) ->
    <%= singular_name %> = @<%= plural_name %>.get(id)

    @view = new <%= "#{view_namespace}.EditView(model: #{singular_name})" %>
    $("#<%= plural_name %>").html(@view.render().el)
  

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-backbone-0.5.1 lib/generators/backbone/scaffold/templates/router.coffee
rails-backbone-0.5.0 lib/generators/backbone/scaffold/templates/router.coffee