简体   繁体   English

Rails 4:application.js中的“ // = require_tree”在/ app / assets / javascripts中不包含我的js文件

[英]Rails 4: “//= require_tree .” in application.js doesn't include my js file in /app/assets/javascripts

I'm trying to follow a tutorial on adding d3.js graph to Rails 4 application. 我正在尝试遵循有关将d3.js图形添加到Rails 4应用程序的教程 The example application is on github and works as expected. 该示例应用程序位于github上 ,并按预期工作。

My problem is that when I try to replicate this application from scratch or add this graph to my existing project the js file in /app/assets/javascripts is not included in resources for some reason despite the fact that the //= require_tree . 我的问题是,当我尝试从头开始复制此应用程序或将此图添加到我的现有项目中时,尽管//= require_tree .出于某种原因, /app/assets/javascripts的js文件未包含在资源中//= require_tree . line is present in /app/assets/javascripts/applications.js files. 行出现在/app/assets/javascripts/applications.js文件中。

I can see this as the only problem since if I paste the code from problematic file into the console, it works. 我可以看到这是唯一的问题,因为如果我将有问题的文件中的代码粘贴到控制台中,它将起作用。

I found similar questions and followed advice given but couldn't fix my problem. 我发现了类似的问题,并听从了建议,但无法解决我的问题。

I've already tried rake assets:precompile suggested here 我已经尝试过rake assets:precompile建议在此处进行 rake assets:precompile

Can anybody help? 有人可以帮忙吗?

I had the same problem. 我有同样的问题。 I had file.coffee and I created file.js which was not added. 我有file.coffee,并创建了未添加的file.js。 When I renamed file.coffee to file.js everything was fine. 当我将file.coffee重命名为file.js时,一切都很好。 However, you could just use www.js2.coffee to convert your js code to coffee and then use the file.coffee file instead. 但是,您可以只使用www.js2.coffee将js代码转换为coffee,然后使用file.coffee文件。

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

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