application.js 未预编译
我不知道为什么,但每当我运行 rake asset:precompile 时,application.js 都不会被编译。我在生产模式下收到“application.js 未预编译”错误。
这是我的 Gemfile(如果它有什么意义的话):
source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'eventmachine', '1.0.0.beta.4.1'
gem 'thin'
gem 'mysql'
gem 'win32-open3-19'
gem 'paperclip', '2.3.8'
#gem 'jammit'
gem 'jsmin'
gem 'will_paginate'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
我制作了一个新的 Rails 应用程序并测试了 rake 资产:预编译并且它正在工作。就相关文件而言,这两个应用程序之间的唯一区别是我安装了哪些 gem。两个应用程序之间的“application.js”是相同的......环境.rb 文件也是如此。
另请注意...当我在 asset/javascripts 目录中包含随机 .js 文件并使用“javascript_include_tag :application”时,开发模式下生成的 URL 之一如下所示: /assets/../javascripts /anytimec.js?body=1
显然它们会失败并返回 404。但是 application.js 文件被正确引用。
更新:
查看 Sprockets 生成的内容,我注意到“逻辑路径”在该位置使用“../javascripts”。我通过分别查看 asset_paths.asset_for('application','js') 和 asset_paths.asset_for('anytimec','js') 的转储来测试这一点。我还将这些转储与新应用程序中的相同文件进行了比较。新的应用程序不会在该位置前面添加“../javascripts”,而我当前的应用程序会这样做。它不会对 CSS 文件或其他任何文件执行此操作...只是 javascript。这绝对是影射核心问题,但我不知道从这里该去哪里。
I'm not sure why, but whenever I run rake assets:precompile
, application.js doesn't get compiled. I get a "application.js isn't precompiled" error in production mode.
Here is my Gemfile if it means anything:
source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'eventmachine', '1.0.0.beta.4.1'
gem 'thin'
gem 'mysql'
gem 'win32-open3-19'
gem 'paperclip', '2.3.8'
#gem 'jammit'
gem 'jsmin'
gem 'will_paginate'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I made a new rails app and tested the rake assets:precompile and it's working. The only difference between the two apps in terms of relevant files would be what gems I have installed. "application.js" is the same between both apps...as are the environment.rb files.
Also of note...when I include a random .js file in my assets/javascripts directory and use "javascript_include_tag :application", one of the resulting URLs in dev mode look like so: /assets/../javascripts/anytimec.js?body=1
and they obviously fail with 404. However the application.js file is referenced correctly.
UPDATE:
Looking into what Sprockets generates I've noticed that the "logical path" uses "../javascripts" in the location. I tested this by looking at the dump of asset_paths.asset_for('application','js') and asset_paths.asset_for('anytimec','js') respectively. I've also compared those dumps to the same files from a fresh application. The fresh application does NOT prepend the "../javascripts" to the location whereas my current app DOES. It doesn't do this to the CSS files or anything else...just javascript. This is most definitely alluding to the core problem but I don't know where to go from here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在发现它与 Sprockets 在读取资产文件夹中专门称为“java”的文件夹时失败有关后,我将其重命名为“applet”并开始工作。
请参阅这篇文章获取答案。
After discovering that it had to do with Sprockets failing when reading a folder specifically called "java" in the assets folder, I renamed it to "applets" and it started working.
See this post for the answer.