我用一个简单的带有索引函数的页面控制器做了一个基本的rails应用程序,当我加载页面时,我得到:

ActionView::Template::Error (application.css isn't precompiled):
    2: <html>
    3: <head>
    4:   <title>Demo</title>
    5:   <%= stylesheet_link_tag    "application" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8: </head>
  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__43625033_88530400'

Gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.0'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

gem 'execjs'
gem 'therubyracer'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

gem 'jquery-rails'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
end

当前回答

我也有这个问题,试图在不预编译的情况下在生产环境中运行,仍然会抛出未预编译的错误。我不得不改变哪一行是注释应用程序。

  # If you precompile assets before deploying to production, use this line
  # Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  Bundler.require(:default, :assets, Rails.env)

其他回答

下面是快速解决方法:

如果你正在使用capistrano,那么就这样把它添加到你的部署中。

after 'deploy:update_code' do
  run "cd #{release_path}; RAILS_ENV=production rake assets:precompile"
end

帽部署

如果你认为你做的一切都很好,但仍然不走运,只要确保你/capistrano在最后运行touch tmp/restart.txt或同等的命令。我在不幸的名单上,但现在:)

我今天遇到了这个错误消息,并想将解决方案发布到我的特定情况。原来,我的问题是,我的css文件之一是缺少一个结束大括号,这是导致文件不被编译。如果您有一个为生产环境设置一切(包括资产预编译)的自动化过程,那么可能很难注意到这一点。

您可能在使用的css中有语法错误。

执行此命令

$ bundle exec rake assets:precompile RAILS_ENV=development --trace

它会给出一个异常,修正后就完成了。

谢谢

对于所有阅读本文但对application.css没有问题的人,而是使用他们的自定义CSS类,例如admin.css, base.css等。

解决方案是使用如上所述

bundle exec rake assets:precompile

样式表中的引用只是引用application.css

<%= stylesheet_link_tag    "application", :media => "all" %>

因为assets pipeline会预编译application.css中的所有样式表。这在开发中也会发生,所以在使用资产管道时使用任何其他引用都是错误的。