简体   繁体   English

ReferenceError:未定义

[英]ReferenceError: is not defined

After I deploy my project on Heroku, I get for the following code in Firebug this error: 在Heroku上部署项目后,在Firebug中获得以下代码此错误:

ReferenceError: SirTrevor is not defined ReferenceError:未定义SirTrevor

<script type="text/javascript" charset="utf-8">
$(function(){
  var instances = $('.sir-trevor-area'),
  l = instances.length;
while (l>=2) {
 instance = $(instances[l]);
 new SirTrevor.Editor({ el: instance, blockTypes: ["Video"], defaultType: "Video" });
 l--;
};
while (l>=1) {
 instance = $(instances[l]);
 new SirTrevor.Editor({ el: instance, blockTypes: ["Embedlylink"], defaultType: "Embedlylink" });
 l--;
};
while (l>=0) {
 instance = $(instances[l]);
 new SirTrevor.Editor({ el: instance, blockTypes: ["Heading", "Text", "Image", "Video", "Embedly"], defaultType: "Text" });
 l--;
};
});
</script> 

Firebug highlights this line " Firebug突出显示了这一行“

new SirTrevor.Editor({ el: instance, blockTypes: ["Heading", "Text", "Image", "Video", "Embedly"], defaultType: "Text" });

"

On localhost everything seems fine, no errors. 在本地主机上,一切似乎都很好,没有错误。 Anyone an idea what the problem could be? 任何人都知道可能是什么问题吗? Thank you so much for your help! 非常感谢你的帮助! Really appreciated! 非常感谢!

UPDATE: 更新:

SirTrevor is defined in sir-trevor.js which is successfully loaded via the Rails asset pipeline in the application.js file. SirTrevor是在sir-trevor.js中定义的,该文件已通过application.js文件中的Rails资产管道成功加载。

This is my application.js file: 这是我的application.js文件:

//= require jquery
//= require jquery_ujs
//= require sir-trevor
//= require underscore.js
//= require eventable.js
//= require twitter/bootstrap
//= require jquery.sidr.js
//= require_tree .

Before push to Heroku I do "rake assets:precompile" . 在推送到Heroku之前,我先进行“ rake asset:precompile”。 On localhost everything seems fine. 在本地主机上,一切似乎都很好。

The application.html.erb header: application.html.erb标头:

<!DOCTYPE html>
<html>
<head>
  <title>Tt</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" rel="stylesheet">
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>

</head>

In order to close the question a short roundup: Thanks to the help of @iamjpg I finally figured it out. 为了结束这个问题,我们简短总结一下:感谢@iamjpg的帮助,我终于弄清楚了。

First I eliminated all the javascript from the <body> and put into separate js files. 首先,我从<body>删除了所有JavaScript,并将其放入单独的js文件中。 Then I adjusted the hierarchy in the application.js file. 然后,我调整了application.js文件中的层次结构。 Sir-Trevor has dependencies to underscore.js and eventable.js, so they have to be higher than sir-trevor.js . Sir-Trevor对underscore.js和eventable.js具有依赖性,因此它们必须高于sir-trevor.js。

//= require jquery
//= require underscore.js
//= require eventable.js
//= require twitter/bootstrap
//= require jquery_ujs
//= require sir-trevor
//= require jquery.sidr.js
//= require_tree .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM