Rails预编译资产 - 无法在本地访问预编译文件

时间:2013-11-27 22:58:52

标签: ruby-on-rails ruby-on-rails-3.2 asset-pipeline assets precompile

我的rails应用程序中有一个神秘的问题,我无法修复。

问题是我想在我部署到服务器之前预先编译我的CSS和JavaScripts并在本地登台环境中运行服务器以检查一切是否正常。

我运行此命令来预编译文件:

rake assets:precompile RAILS_ENV=staging

要在登台环境中启动服务器,请运行以下命令:

rails s -e staging

文件正在成功预编译并放在public / assets文件夹中,但无法在浏览器中加载,我也无法从浏览器手动访问文件。

我的staging.rb环境文件如下所示:

 # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false
  config.static_cache_control = "public, max-age=2592000"
  config.action_controller.perform_caching = true

  # Compress JavaScripts and CSS
  config.assets.compress = true
  config.assets.debug = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

  # Generate digests for assets URLs
  config.assets.digest = true
  config.assets.initialize_on_precompile = true

  # Use a different cache store in production
  #config.cache_store = :dalli_store, 'localhost:11211'


  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
  config.assets.precompile += %w( .svg .eot .woff .ttf )

使用以下版本的ruby和rails:

Ruby v.1.9.3 Rails v.3.2.14

1 个答案:

答案 0 :(得分:0)

通过排除该行来解决问题:

config.serve_static_assets = false