我用一个简单的带有索引函数的页面控制器做了一个基本的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)

其他回答

我在开发环境中也犯了完全相同的错误。最后,我所需要做的就是修改它:

config.assets.manifest = Rails.root.join("public/assets")

到我的配置/环境/开发。Rb文件,它修复了它。我在开发中与资产相关的最终配置如下:

config.assets.compress = false  
config.assets.precompile += %w[bootstrap-alerts.js] #Lots of other space separated files
config.assets.compile = false
config.assets.digest = true
config.assets.manifest = Rails.root.join("public/assets")
config.assets.debug = true

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

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

  # 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用户是把这一行到Capfile

# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'

在heroku服务器(只读文件系统), 如果你想运行时编译css(不建议,但你可以这样做),确保你已经做了如下设置-

# inside config/application.rb
config.assets.enabled = true
config.assets.prefix = Rails.root.join('tmp/assets').to_s

# If you are using sass then keep gem outside of asset group
 gem 'sass-rails',   '3.1.4'

# inside config/environments/production.rb
config.assets.compile = true