【问题标题】:Rails precompile assets - Cannot access precompiled files locallyRails 预编译资产 - 无法在本地访问预编译文件
【发布时间】:2013-12-13 19:39:37
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    通过注释行解决了问题:

    config.serve_static_assets = false
    

    【讨论】:

    • 测试后记得rm -rf public/assets,否则你的开发服务器会加载旧的预编译文件并忽略最近的代码更改
    猜你喜欢
    • 1970-01-01
    • 2012-03-26
    • 2017-04-17
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 2013-09-27
    相关资源
    最近更新 更多