Rails 4.1.1:lib / assets / javascripts中的JS文件没有加载

时间:2015-02-21 10:45:18

标签: javascript ruby-on-rails

我有一个包含一个函数的小型JS文件(common.js)。我在application.js中有以下几行:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery.readyselector
//= require common
//= require_tree .

当我将其存储在

中时
app/assets/javascripts

vendor/assets/javascripts

文件已正确加载,但当我将其移至

lib/assets/javascripts

它停止工作,我收到错误:

Sprockets::FileNotFound
couldn't find file 'common'
(in C:/Sites/rails_studio/beatjoe/app/assets/javascripts/application.js:21)

所有这些都是我的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

根据文档,由于

,不仅应包括common.js
//= require common

但也被

抓住了
//= require_tree .

我错过了什么?

1 个答案:

答案 0 :(得分:5)

通过在本地服务器运行时创建 lib / assets / javascript 目录,我能够重现Sprockets::FileNotFound错误。您似乎需要重新启动服务器以获取目录更改。

既然您的服务器已经重新启动,您应该能够在不重新启动服务器的情况下将文件添加到目录中。