ruby on rails - Backbone.js view not inserting template -
i creating user views backbone/rails application. attempting add new view:
/views/users/edit.js.coffee
class mosaikbackbone.views.usersedit extends backbone.view template: jst['users/edit'] render: -> $(@el).html(@template()) the template in /templates/users/edit.jst.eco
<h1>edit page</h1> my router looks in /routers/users.js.coffee:
class mosaikbackbone.routers.users extends backbone.router routes: '': 'index' 'users/:id': 'show' 'users/edit/:id': 'update' initialize: -> @collection = new mosaikbackbone.collections.users() @collection.fetch() index: -> view = new mosaikbackbone.views.usersindex(collection: @collection) $('#container').html(view.render().el) show: (id) -> alert "entry #{id}" update: (id) -> editview = new mosaikbackbone.views.usersedit() $('#container').html(editview.render().el) the index views/templates work fine, , view being inserted container div. if change tagname usersedit view 'li' can see li element in dom, it's not being populated template. i'm guess it's syntax issue there no errors in console.
update: clarify, view being appended #container because can see empty element item, there issue rendering template.
i refer template: jst['users/index'] in usersindex view , works fine. reason template: jst['users/edit'] isn't working though both templates in same folder. also, can place invalid syntax in edit template , no errors thrown it's not being detected dont' think
update 2: following view/templates works without issue:
class mosaikbackbone.views.usersindex extends backbone.view template: jst['users/index'] initialize: -> @collection.on('reset', @render, this) @collection.on('add', @appenduser, this) render: -> $(@el).html(@template()) @collection.each(@appenduser) appenduser: (user) -> view = new mosaikbackbone.views.user(model: user) $('#users').append(view.render().el) templates/users/index.jst.eco
h1>title here</h1> <ul id="users"></ul>
Comments
Post a Comment