简体   繁体   English

将引导程序主题安装到Rails 4应用中-javascript文件出现问题

[英]Install bootstrap theme into Rails 4 app - Issue with javascript files

I downloaded a theme from WrapBootstrap.com and am trying to implement it into a new rails 4.1 application. 我从WrapBootstrap.com下载了一个主题,并试图将其实现到新的Rails 4.1应用程序中。

I was given four directories - css,fonts,img, and js. 我得到了四个目录-css,fonts,img和js。 I was also given the index.html file. 还为我提供了index.html文件。

I copied the index.html file over into my app and am routing to it. 我将index.html文件复制到了我的应用程序中并路由到它。 I then took the contents of each directory given to me and placed it in the appropriate assets directory: 然后,我获取分配给我的每个目录的内容,并将其放在适当的资产目录中:

css went to stylesheets , img went to images , js went to javascripts . css转到stylesheetsimg转到imagesjs转到javascripts I am not sure what to do with the fonts directory. 我不确定该使用fonts目录。

Then, I had a lot of requirements like this in my index.html.erb file: 然后,我在index.html.erb文件中有很多这样的要求:

These existed for both javascript and css. 这些对于javascript和css都存在。 I took all of them out and replaced it with these lines of code: 我将它们全部取出,并用以下代码行替换了它们:

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>

And I have this in each of the application.css and application.js files: 我在每个application.css和application.js文件中都有此文件:

//= require_tree .
//= require_self

and

*= require_tree .
*= require_self

Now, it appears that the CSS is rendering correctly. 现在,看来CSS正确呈现了。 However, the JS files are not loading at all. 但是,JS文件根本没有加载。 I can take them out of the app entirely and I get the same result. 我可以将它们完全从应用程序中删除,并且得到相同的结果。

What am I missing here? 我在这里想念什么? The js files are in the asset directory, they are being required in application.js , and I have included application.js in my index.html.erb file. js文件位于资产目录中,在application.js中是必需的,并且我在index.html.erb文件中包含了application.js

Any thoughts? 有什么想法吗?

As you have external assets that are going to be used in your app, the Rails convention is to put them in the vendor/assets path. 当您拥有将在您的应用程序中使用的外部资产时,Rails约定就是将它们放在vendor/assets路径中。 You can copy the corresponding files to their directories. 您可以将相应的文件复制到其目录中。 The fonts should be inside the stylesheets folder. fonts应位于stylesheets文件夹中。

Then in your application.js add this line (one for each file you have): 然后在application.js中添加以下行(每个文件一个):

//= require name-of-js-file-without-extention

And in your application.css add this: 并在您的application.css中添加以下内容:

*= require name-of-css-file-without-extention

At this point your css and js should be working :) 此时,您的CSS和JS应该可以正常工作了:)

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

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