Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AssetNotPrecompiledError when using html5-rails gem in production env

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.

like image 475
stephenmurdoch Avatar asked Sep 14 '11 18:09

stephenmurdoch


1 Answers

I managed to fix this by adding polyfills.js to application.rb

config.assets.precompile += %w( polyfills.js )
like image 110
stephenmurdoch Avatar answered Sep 28 '22 04:09

stephenmurdoch