在生产环境中使用html5-rails gem时出现AssetNotPrecompiledError

ste*_*och 5 ruby-on-rails ruby-on-rails-3.1 asset-pipeline

我已经在rails 3.1上开发了html5-railscompass-html5但是当我在生产模式下运行我的应用程序并尝试访问我的主页时,我得到以下内容:

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index

polyfills.js isn't precompiled
Run Code Online (Sandbox Code Playgroud)

问题是localhost:8080:/assets/polyfills.js确实显示.我怀疑我的方法有问题:

重现步骤:

1使用家庭控制器创建新的rails应用程序,索引操作并设置根路由并删除public/index.htmlviews/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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

5运行RAILS_ENV=production bundle exec rake assets:precompile

6运行unicorn -E production(或者rails s -e production如果你在webrick上)并访问root url

7观察错误

正确缩小的response-md5.min.jsmodernizr-md5.min.js存在于/ public/assets中.当我访问localhost:8080/assets/modernizr.min.js时,编译的js代码会出现.当我尝试访问我的主页时,抛出了服务器错误.

我怀疑我的方法有错误.我也问了同样的问题在这里 GitHub上.

ste*_*och 6

我设法通过将polyfills.js添加到application.rb来解决这个问题

config.assets.precompile += %w( polyfills.js )
Run Code Online (Sandbox Code Playgroud)