Ruby on rails 带主干和把手的栏杆

Ruby on rails 带主干和把手的栏杆,ruby-on-rails,backbone.js,handlebars.js,backbone-views,Ruby On Rails,Backbone.js,Handlebars.js,Backbone Views,关于我的应用程序: -我将Rails 3.2.6与backbone.js(Rails上的主干gem)和Handlebar模板引擎一起使用。 -创建了一个路线和视图,效果非常好。我的看法是: el: $('#lorem'), render: function(){ var js = this.collection.toJSON(); var template = Handlebars.compile($("#lorem2").html()); $(this.el).

关于我的应用程序:
-我将Rails 3.2.6与backbone.js(Rails上的主干gem)和Handlebar模板引擎一起使用。
-创建了一个路线和视图,效果非常好。我的看法是:

  el: $('#lorem'),
  render: function(){
    var js = this.collection.toJSON();
    var template = Handlebars.compile($("#lorem2").html());
    $(this.el).html(template({articles: js}));
    console.log(js);
    return this;
  }
-我创建了一个模板(在资产目录:assets/templates/peoples/index.hbs中):


{{#每篇文章}
{{this.name}}
{{/每个}}
刷新页面时,我收到以下错误消息:

未捕获的TypeError:无法调用null的方法“match”

我认为模板文件可能错误:

<script src="/assets/templates/people/index.js?body=1" type="text/javascript"></script>

这包括:

    (function() {
            this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
            this.HandlebarsTemplates["people/index"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  helpers = helpers || Handlebars.helpers;
  var buffer = "", stack1, foundHelper, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;


  buffer += "<div class=\"entry\">\n  <h1>";
  foundHelper = helpers.title;
  stack1 = foundHelper || depth0.title;
  if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
  else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "title", { hash: {} }); }
  buffer += escapeExpression(stack1) + "</h1>\n  <div class=\"body\">\n    ";
  foundHelper = helpers.body;
  stack1 = foundHelper || depth0.body;
  if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
  else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "body", { hash: {} }); }
  if(stack1 || stack1 === 0) { buffer += stack1; }
  buffer += "\n  </div>\n</div>\n";
  return buffer;});
            return HandlebarsTemplates["people/index"];
          }).call(this);
(函数(){
this.HandlebarsTemplates | |(this.HandlebarsTemplates={});
this.handlebar.templates[“people/index”]=handlebar.template(函数(handlebar、depth0、helpers、partials、data){
助手=助手| |把手.助手;
var buffer=“”,stack1,foundHelper,self=this,functionType=“function”,helperMissing=helpers.helperMissing,undf=void 0,escapeeexpression=this.escapeeexpression;
缓冲区+=“\n”;
foundHelper=helpers.title;
stack1=foundHelper | | depth0.title;
if(typeof stack1==functionType){stack1=stack1.call(depth0,{hash:{}});}
如果(stack1==unde){stack1=helperMissing.call(depth0,“title”,{hash:{}});}
缓冲区+=转义表达式(堆栈1)+“\n\n”;
foundHelper=helpers.body;
stack1=foundHelper | | depth0.body;
if(typeof stack1==functionType){stack1=stack1.call(depth0,{hash:{}});}
如果(stack1==unde){stack1=helperMissing.call(depth0,“body”,{hash:{}});}
如果(stack1 | | stack1==0){buffer+=stack1;}
缓冲区+=“\n\n\n”;
返回缓冲区;});
返回车把模板[“人员/索引”];
}).打电话(这个);

/assets/templates/people/index.js中出现的混乱表明您的把手模板在JavaScript代码看到之前就已经编译成JavaScript了

如果您说
$(x).html()
x
与任何内容都不匹配,您将返回一个
null
。因此,您的DOM中可能根本没有
#lorem2
,您只在
HandlebarsTemplates[“people/index”]
中有编译后的模板。这意味着
渲染的这一部分:

var template = Handlebars.compile($("#lorem2").html());
将失败并向您提供
TypeError
异常。尝试将其替换为:

var template = HandlebarsTemplates['people/index'];
var template = HandlebarsTemplates['people/index'];