简体   繁体   English

编译的Javascript无法在生产模式下运行

[英]Compiled Javascript not Working in Production Mode

I am building an app on my local machine. 我正在本地计算机上构建应用程序。 When I precompile and run it in production mode, the compiled javascript stops working. 当我预编译并在生产模式下运行它时,已编译的javascript将停止工作。 Specifically, I have javascript in one coffeescript file and application.js, both in the assets folder. 具体来说,我在资产文件夹中的一个coffeescript文件和application.js中都有javascript。 All other javascript (ie jquery in ajax forms, etc) continues to work, which is why I think it must have to do with compilation. 所有其他javascript(即ajax形式的jquery等)继续工作,这就是为什么我认为它必须与编译有关。

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

//= require jquery
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require jquery-ui/dialog
//= require autocomplete-rails
//= require dresssed
//= require raphael
//= require morris
//= require best_in_place
//= require_tree .

$('.label-stock-health').popover({ html : true});

$(document).keypress(function(e) {
    if ($('.search-bar').length){
      if($(".search-bar").is(":visible")) {

      } else {
        $(".search-bar").show();
        $("#q_name_cont").focus();
      }
    }

});

$("#spinner").hide();

$(document).ajaxStart(function() {
    $("#spinner").fadeIn('slow');
  }).ajaxStop(function() {
      $("#spinner").hide();
  });

$(document).ready(function() {
        $(".show-search").click(function(){
        if ($('.search-bar').length){
            $(".search-bar").toggle();
          }
        });
        $(".best_in_place").best_in_place();
});

This functionality still works in development mode. 此功能仍可在开发模式下使用。 Additionally, if I hard code the javascript into my layout template, it will work. 此外,如果我将javascript硬编码到布局模板中,它将可以正常工作。 But without the hardcoding, it does not. 但是,如果没有硬编码,事实并非如此。

Any advice on what might be the culprit? 对什么可能是罪魁祸首有何建议? If not , what is the best way to go about debugging this? 如果不是,进行调试的最佳方法是什么?

UPDATE #1 The only two errors I am seeing in the Javascript console of Chrome developer tools are posted below. 更新#1以下是我在Chrome开发人员工具的Javascript控制台中看到的仅有的两个错误。 They also show on my localhost development instance, where my javascript functionality is working in full. 它们还显示在我的localhost开发实例上,我的javascript功能已在其中完全运行。

Uncaught Google Maps API is required. 需要未捕获的Google Maps API。 Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.(anonymous function) @ application-6ab26aa5fc5d647a3b5543af7c9838a6.js:9t.(anonymous function) @ application-6ab26aa5fc5d647a3b5543af7c9838a6.js:9(anonymous function) @ application-6ab26aa5fc5d647a3b5543af7c9838a6.js:9 variants:565 GET http://www.example.com/bootstrap/glyphicons-halflings-regular.woff2 404 (Not Found) 请注册以下JavaScript库http://maps.google.com/maps/api/js?sensor=true 。(匿名函数)@ application-6ab26aa5fc5d647a3b5543af7c9838a6.js:9t。(匿名函数)@ application-6ab26aa5fc5d647a3b5543af7c9838a6.js: 9(匿名函数)@ application-6ab26aa5fc5d647a3b5543af7c9838a6.js:9变体:565 GET http://www.example.com/bootstrap/glyphicons-halflings-regular.woff2 404(未找到)

I did wrote to you in upwork.com how ever here it is... If it is working in local host but when uploaded online stops working than it is permissions problem. 我确实在upwork.com上给您写过信,这是怎么回事...如果它在本地主机上运行,​​但在线上载停止工作,则是权限问题。 I have encounter same problems in godady and blue host. 我在Godady和Blue Host中也遇到了相同的问题。 Try playing with permissions. 尝试使用权限播放。 For (on blue host) worked permissions to be set at 5 5 4. or 5 5 5 I did not remember correctly. 对于(在蓝色主机上)将工作权限设置为5 5 4或5 5 5,我记不清了。 How ever delete all and reupload with new permissions once you figure out what they should be. 确定所有权限后,如何删除所有权限并重新上传新权限。

The culprit here is the popover line, you will need to include the popover plugin if you want to use it. 罪魁祸首是popover行,如果要使用它,您将需要包括popover插件。 Comment it out and deploy your code, it will start working again. 将其注释掉并部署您的代码,它将重新开始工作。

I've just sent you a message on upwork as well, but you should check if removing turbolinks from your application.js files resolves the issue: 我也刚刚向您发送了有关升级工作的消息,但是您应该检查是否从application.js文件中删除了涡轮链接可以解决此问题:

 //= require jquery
 //= require jquery_ujs
 //= require turbolinks ** remove this line as turbolinks interferes with javascript occasionally.
 //= require_tree .

Please include another file name custom.js and updated 请添加另一个文件名custom.js并更新

$(document).ajaxStart(function() {
       $("#spinner").fadeIn('slow');
 });
$(document).ajaxStop(function() {
     $("#spinner").hide();
 });

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

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