【问题标题】:AssetNotPrecompiledError when using html5-rails gem in production env在生产环境中使用 html5-rails gem 时出现 AssetNotPrecompiledError
【发布时间】:2011-09-14 18:19:15
【问题描述】:

我有 html5-railscompass-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.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

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=production bundle exec rake assets:precompile

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

7观察错误

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

我怀疑我的方法有错误。我在 github 上问过同样的问题 here

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 asset-pipeline


    【解决方案1】:

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

    config.assets.precompile += %w( polyfills.js )
    

    【讨论】:

      【解决方案2】:

      我刚刚遇到同样的错误,问题是我的文件丢失了...

      【讨论】:

        猜你喜欢
        • 2012-05-06
        • 2021-12-13
        • 2015-08-19
        • 1970-01-01
        • 2013-03-20
        • 1970-01-01
        • 2014-01-28
        • 2014-06-02
        • 2016-11-13
        相关资源
        最近更新 更多