简体   繁体   中英

Rails 4.1.1: JS file in lib/assets/javascripts doesn't load

I have a small JS file (common.js) containing one function. I have the following lines in 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:

- 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

//= 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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