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

发布于 2024-12-04 08:47:26 字数 1846 浏览 0 评论 0原文

我有 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=生产包执行rake资产:预编译

6运行unicorn -E生产(或rails s -e生产 如果你在webrick)并访问根 url

7 观察 bug

存在正确缩小的 respond-md5.min.jsmodernizr-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二手情话 2024-12-11 08:47:26

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

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

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

config.assets.precompile += %w( polyfills.js )
幼儿园老大 2024-12-11 08:47:26

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

i just got the same error, and the issue was that my file was missing...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文