MSC
MSC

Reputation: 3386

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?

Upvotes: 2

Views: 2437

Answers (1)

Jordan Allan
Jordan Allan

Reputation: 4486

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.

Upvotes: 5

Related Questions