1

Solved:

I have a backbone(0.9.2) written in coffeescript as follows

class Animal.Views.Cats extends Backbone.View
 template: JST['animals/cats']
 ...
 ...
 render: ->
  $(@el).html(@template())
  this

With this coffeescript code, when i execute in browser, i get the following error in console

Property template of object <#cat> is not a function

I am using eco template with rails 3.1 backend where am i going wrong?

solution:

the problem was a deeply nested template file structure

template: JST['mammals/animals/cats'] fixes the problem

railerhelper
  • 103
  • 9

2 Answers2

2

To reiterate, if you have a directory structure like this:

app/assets/templates/namespace/animals/cats.jst.eco

You need to include your namespace when referencing your template:

  • Will not work: JST['animals/cats']
  • Will work: JST['namespace/animals/cats']
Andrew
  • 227,796
  • 193
  • 515
  • 708
1

in your code 'template' is not defined as a function but as a attribute.

try

template: -> JST['animals/cats']

ie, insert the function arrow '->'

or, if you do not want that to be a function, then drop the parentheses after @template

$(@el).html @template
francpaul
  • 246
  • 1
  • 5