简体   繁体   English

Ruby on Rails:我的部分资产(javascripts)的资产管道失败

[英]Ruby on Rails: Asset pipeline failing for only some of my assets (javascripts)

In my application.js I have 在我的application.js我有

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require s3_direct_upload
//= require_tree .

I also have 4 javascript files in the javascript folder other application.js. 我在javascript文件夹中还有4个javascript文件,其他application.js。 They are: users.js, access.js, documents.js, and bands.js. 它们是:users.js,access.js,documents.js和bands.js。

I wrote some javascript code in documents.js and it worked fine. 我在documents.js中写了一些javascript代码并且工作正常。 I then tried writing code in bands.js and nothing happened, as if the javascript file were not even loaded. 然后我尝试在bands.js中编写代码,没有任何反应,好像javascript文件甚至没有加载。 I then decided to do a simple test and wrote an alert("Hello"); 然后我决定做一个简单的测试并写一个警报(“你好”); message at the top of each of my javascripts and it turns out that the alert message only pops up for documents.js and users.js, not for any of the others (that is, when I visit the index page for the corresponding views). 在我的每个javascripts顶部的消息,事实证明,仅为documents.js和users.js弹出警报消息,而不是为任何其他人(即,当我访问相应视图的索引页面时) 。 It seems kind of random. 这似乎是随机的。 I have tried restarting my server a few times and nothing changed. 我曾尝试重启我的服务器几次,没有任何改变。 This seems really odd to me. 这对我来说真的很奇怪。 I couldn't think of any code to provide that would be useful but let me know if there's some code you would like to see. 我想不出任何提供有用的代码但请告诉我是否有一些您希望看到的代码。 How can I make my javascript responsive across all pages that they supposedly apply to? 如何让我的javascript响应他们认为适用的所有页面? Please help!! 请帮忙!!

I would remove require_tree . 我会删除require_tree . and require each js file individually 并单独要求每个js文件

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require s3_direct_upload
//= require //= require jquery
//= require jquery_ujs
//= require turbolinks
//= require s3_direct_upload
//= require user
//= require access
//= require documents

This way you know what's being included and this works for you because you don't have a lot of js files. 这样你就知道包含了什么,这对你有用,因为你没有很多js文件。

Then go to your browser console and expand <head> element and make sure js file that you need is being included, hit search and search your file name. 然后转到浏览器控制台并展开<head>元素并确保包含所需的js文件,点击搜索并搜索您的文件名。

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

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