简体   繁体   English

Rails应用程序未加载特定的JavaScript文件

[英]Rails app does not load a specific JavaScript file

I currently try to port this template from startbootstrap.com into my rails app. 我目前正在尝试将该模板startbootstrap.com移植到我的Rails应用程序中。 Most of it already works but the navigation bar does not change its color while scrolling. 它的大多数已经可以使用,但是导航栏在滚动时不会更改其颜色。

The different colors are achieved by the creative.js file. 不同的颜色由creative.js文件实现。 I put this file under assets/javascript and included as in my application.js file: 我将此文件放在assets / javascript下,并包含在我的application.js文件中:

//= require jquery
//= require bootstrap.min
//= require jquery.easing.min
//= require jquery.fittext
//= require wow.min
//= require creative
//= require jquery_ujs
//= require turbolinks
//= require_tree .

I inspected the assets with the Chrome Developer Tools and the creative.js file does not appear there. 我使用Chrome开发者工具检查了资产,但creative.js文件未显示在此处。 Since the other javascript files appear in the asset folder the asset pipeline seems to be working. 由于其他JavaScript文件出现在资产文件夹中,因此资产管道似乎正在运行。 What do I have to change so that the creative.js file appears in my assets too? 为了使creative.js文件也出现在我的资产中,我需要更改什么?

I faced the same issue with my project where I tried to incorporate Bootstrap's creative theme. 在我的项目中,我尝试结合Bootstrap的创意主题时遇到了同样的问题。 The issue for me was that creative.js was not included at the right position (if you notice in the original theme the JS script calls are made at the end of the HTML file, after all the class and id declarations). 对我来说,问题是没有在正确的位置包含creative.js(如果您在原始主题中注意到JS脚本调用是在所有类和id声明之后在HTML文件的末尾进行的)。

Your order of inclusion inside application.js is correct => 您在application.js的包含顺序正确=>

//= require jquery
//= require bootstrap.min
//= require jquery.easing.min
//= require jquery.fittext
//= require wow.min
//= require creative
//= require jquery_ujs
//= require turbolinks
//= require_tree .

However, there is a good chance that application.js is not included at the right spot. 但是,很有可能没有在正确的位置包含application.js Ensure that you are including the files after the below code segment has ended => 确保以下代码段结束后包括文件=>

<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">

Best of luck! 祝你好运!

Try to delete the coffee file with the same name. 尝试删除具有相同名称的咖啡文件。 In your case creative.coffee 就您而言, creative.coffee

It worked for me! 它为我工作!

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

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