在生产环境中使用 html5-rails gem 时出现 AssetNotPrecompiledError
我有 html5-rails 和 compass-html5 在 Rails 3.1 上进行开发,但是当我在生产模式下运行我的应用程序并尝试访问我的主页时,我得到以下信息
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index
polyfills.js isn't precompiled
: localhost:8080:/assets/polyfills.js 确实显示。我怀疑我的方法有问题:
重现步骤:
1使用家庭控制器创建新的 Rails 应用程序、索引操作并设置根路由并删除 public/index.html 和 views/layouts/application.html.erb
2 将以下内容添加到 Gemfile
gem 'rails', '~> 3.1.0'
gem 'unicorn'
group :assets do
gem 'compass', "~> 0.12.alpha.0"
gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'compass-html5', :git => 'https://github.com/sporkd/compass-html5.git'
gem 'html5-rails', :git => "https://github.com/sporkd/html5-rails.git"
end
3 运行 Rails g html5:install
创建/config/compass.rb 文件
4 创建包含以下代码的/config/initializers/sass.rb:
Rails.configuration.sass.tap do |config|
config.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
end
5运行RAILS_ENV=生产包执行rake资产:预编译
6运行unicorn -E生产
(或rails s -e生产
如果你在webrick)并访问根 url
7 观察 bug
存在正确缩小的 respond-md5.min.js 和 modernizr-md5.min.js在/public/assets中。当我访问localhost:8080/assets/modernizr.min.js时,编译的js代码确实出现了。当我尝试访问我的主页时抛出服务器错误。
我怀疑我的方法有问题。我在 github 上此处提出了同样的问题。
I've got html5-rails and compass-html5 working in devlopment on rails 3.1 but when I run my app in production mode and try to visit my homepage, I get the following:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index
polyfills.js isn't precompiled
The thing is that localhost:8080:/assets/polyfills.js does display. I suspect there is a problem with my methods:
Steps to reproduce:
1 Create new rails app with home controller, index action and set up a root route and delete public/index.html and views/layouts/application.html.erb
2 Add following to Gemfile
gem 'rails', '~> 3.1.0'
gem 'unicorn'
group :assets do
gem 'compass', "~> 0.12.alpha.0"
gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'compass-html5', :git => 'https://github.com/sporkd/compass-html5.git'
gem 'html5-rails', :git => "https://github.com/sporkd/html5-rails.git"
end
3 Run rails g html5:install
to create /config/compass.rb file
4 Create /config/initializers/sass.rb containing following code:
Rails.configuration.sass.tap do |config|
config.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
end
5 Run RAILS_ENV=production bundle exec rake assets:precompile
6 Run unicorn -E production
(or rails s -e production
if you're on webrick) and visit root url
7 Observe bug
The correctly minified respond-md5.min.js and modernizr-md5.min.js are present in /public/assets. The compiled js code does appear when I visit localhost:8080/assets/modernizr.min.js. The server error is thrown when I try to visit my homepage.
I suspect there is an error in my method. I have asked the very same question here on github.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法通过将 polyfills.js 添加到 application.rb 来解决此问题
I managed to fix this by adding polyfills.js to application.rb
我刚刚遇到同样的错误,问题是我的文件丢失了......
i just got the same error, and the issue was that my file was missing...