[英]Rails 4.1.1: JS file in lib/assets/javascripts doesn't load
I have a small JS file (common.js) containing one function. 我有一个包含一个功能的小JS文件(common.js)。 I have the following lines in application.js: 我在application.js中有以下几行:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery.readyselector
//= require common
//= require_tree .
When I store it in 当我存储在
app/assets/javascripts
or 要么
vendor/assets/javascripts
the file is loaded properly, but when I move it to 该文件已正确加载,但是当我将其移至
lib/assets/javascripts
it stops working and I get the error: 它停止工作,我得到了错误:
Sprockets::FileNotFound
couldn't find file 'common'
(in C:/Sites/rails_studio/beatjoe/app/assets/javascripts/application.js:21)
All this eventhough my Rails.application.config.assets.paths is: 尽管我的Rails.application.config.assets.paths是所有这些:
- C:/Sites/rails_studio/myappname/app/assets/images
- C:/Sites/rails_studio/myappname/app/assets/javascripts
- C:/Sites/rails_studio/myappname/app/assets/stylesheets
- C:/Sites/rails_studio/myappname/lib/assets/javascripts
- C:/Sites/rails_studio/myappname/vendor/assets/fonts
- C:/Sites/rails_studio/myappname/vendor/assets/images
- C:/Sites/rails_studio/myappname/vendor/assets/javascripts
- C:/Sites/rails_studio/myappname/vendor/assets/stylesheets
- C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.3.0/lib/assets/javascripts
- C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/jquery-rails-3.1.2/vendor/assets/javascripts
- C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/coffee-rails-4.0.1/lib/assets/javascripts
According to the documentation, not only should common.js be included due to 根据文档,由于以下原因,不仅应该包括common.js:
//= require common
but also be caught by 但也被
//= require_tree .
What am I missing? 我想念什么?
I was able to reproduce the Sprockets::FileNotFound
error by creating the lib/assets/javascript directory while the local server was running. 通过在本地服务器运行时创建lib / assets / javascript目录,我能够重现Sprockets::FileNotFound
错误。 It appears you need to restart the server to pick up directory changes. 看来您需要重新启动服务器才能获取目录更改。
Now that your server has since been restarted, you should be able to add files to the directory without restarting your server. 既然您的服务器已经重新启动,那么您应该能够在不重新启动服务器的情况下将文件添加到目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.