简体   繁体   English

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

[英]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.

相关问题 Rails 4:application.js中的“ // = require_tree”在/ app / assets / javascripts中不包含我的js文件 - Rails 4: “//= require_tree .” in application.js doesn't include my js file in /app/assets/javascripts Meteor.js不会加载lib文件夹的内容 - Meteor.js doesn't load content of lib folder js在Rails上无法正确加载ruby - js doesn't load properly with ruby on rails 在我运行 rails assets:precompile 之前,Rails 应用程序不会加载对 Javascript 文件的更新 - Rails app doesn't load updates to Javascript files until I run rails assets:precompile Rails递归地包含javascripts资源文件夹 - Rails include javascripts assets folder recursively Rails应用程序未使用资产加载javascripts文件 - Rails application not loading javascripts files using assets 将JS代码迁移到Rails应用程序中的资产/ JavaScript之后,会话变量不再被识别 - session variable is not recognized anymore after migrating js code to assets/javascripts in rails app `application.js`不再包括Rails 3.1应用程序的app / assets / javascripts中的所有脚本 - `application.js` no longer including all scripts in app/assets/javascripts for Rails 3.1 app 如何从Rails的“查看”页面中的/ app / assets / javascripts文件夹中调用JS脚本? - How can I call upon a JS script in my /app/assets/javascripts folder from a View page in Rails? 'createConsumer' 不是由 node_modules/@rails/actioncable/app/assets/javascripts/action_cable.js 导出的 - 'createConsumer' is not exported by node_modules/@rails/actioncable/app/assets/javascripts/action_cable.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM