简体   繁体   English

尝试将外部JS和CSS文件添加到我的rails应用程序

[英]Trying to add external JS and CSS files to my rails app

I am trying to add external css and JS to my rails app. 我正在尝试将外部css和JS添加到我的rails应用程序中。 I added the relevant files in vendor/assets/javascripts and vendor/assets/stylesheets. 我在vendor / assets / javascripts和vendor / assets / stylesheets中添加了相关文件。

I tried to load these files in my app by adding these lines to application.scss : 我尝试通过将这些行添加到application.scss来在我的应用程序中加载这些文件:

@import "stylesheets/nice-select.css";
@import "stylesheets/style.css";

and these lines to application.js : 这些行到application.js:

//= require javascripts/fastclick.js
//= require javascripts/nice_select.js
//= require javascripts/prism.js

When I try to launch my app after restarting the server I get : 当我在重新启动服务器后尝试启动我的应用程序时,我得到:

couldn't find file 'javascripts/fastclick.js' with type 'application/javascript' 无法找到类型为'application / javascript'的文件'javascripts / fastclick.js'

However the file fastclick.js is here inside vendor/assets/javascripts. 但是文件fastclick.js在vendor / assets / javascripts中。

What am I doing wrong when I try to include these external files ? 当我尝试包含这些外部文件时,我做错了什么?

Are you using Rails 4? 你在使用Rails 4吗? If so, you shouldn't need to include javascripts in your script path: 如果是这样,您不需要在脚本路径中包含javascripts

//= require fastclick.js
//= require nice_select.js
//= require prism.js

Should work for vendor/assets/javascripts/fastclick.js , etc... 应该适用于vendor/assets/javascripts/fastclick.js等...

If it still doesn't work, add the following in your configuration block within application.rb : 如果它仍然不起作用,请在application.rb中的配置块中添加以下内容:

config.assets.paths << Rails.root.join('vendor', 'assets', 'javascripts')

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

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