我在/app/vendor/assets/javascripts/
路径中的Rails应用程序中有2个JavaScript文件。假设这些文件是jsfile-1.js
和jsfile-2.js
。在jsfile-2.js
我有我在我看来(views/name/name.html.erb
)使用这两个文件下面的代码如何在Rails中的另一个JavaScript文件中使用JavaScript文件路径
var myWorker = new Worker("jsfile-1.js");
first.onchange = function() {
myWorker.postMessage([first.value,second.value]);
console.log('Message posted to worker');
}
。在将这两行我/app/assets/javascripts/application.js
:
//= require jsfile-1
//= require jsfile-2
现在,当我访问http://localhost:3000/name/name的页面(在我的情况,控制器名称相同动作的名称),我收到我的检查元素控制台(在Firefox以下错误浏览器):
GET http://localhost:3000/name/jsfile-1.js [HTTP/1.1 404 Not Found 541ms]
NetworkError: Failed to load worker script at "jsfile-1.js"
如果我写的new Worker("javascripts/jsfile-1.js")
代替new Worker("jsfile-1.js")
,想必我得到这个错误,而不是:
GET http://localhost:3000/name/javascripts/jsfile-1.js [HTTP/1.1 404 Not Found 541ms]
我尝试了许多不同的路径,似乎没有任何工作。什么是正确的道路?
JavaScript文件本身加载就好了,因为我将它们添加到'application.js'中。由于'var myWorker = new Worker(“jsfile-1.js”)'行,问题正在发生。似乎无法弄清楚发生了什么事:/ –