I am creating user views for my Backbone/rails application. I am attempting to add a new view:
/views/users/edit.js.coffee
class MosaikBackbone.Views.UsersEdit extends Backbone.View
template: JST['users/edit']
render: ->
$(@el).html(@template())
this
The template is in /templates/users/edit.jst.eco
<h1>edit page</h1>
My router looks like this 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, and the view is being inserted into the container div. If I change the tagName for the UsersEdit view to 'li' I can see the li element in the DOM, it's just not being populated with the template. I'm guess it's a syntax issue but there are no errors in the console.
UPDATE: Just to clarify, the view is being appended to #container
because i can see the empty element item, there is just an issue with rendering the template.
I refer to template: JST['users/index']
in my UsersIndex view and everything works fine. For some reason template: JST['users/edit']
isn't working even though both templates are in the same folder. Also, I can place invalid syntax in the edit template and no errors are thrown so it's not even being detected I dont' think
UPDATE 2: The 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)
this
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>
the edit template should be working and this should show in console
↵↵" __proto__: Object – kcurtin Jun 05 '12 at 21:50