【发布时间】:2015-12-04 23:38:26
【问题描述】:
我有一个 Rails 4.2 应用程序,它使用 Heroku 上的预编译资产运行。我们正在尝试迁移到新平台 (Aptible),但使用相同的设置,我们的应用程序无法再正确获取资产。是的,我运行 bundle exec rake assets:precompile 来预编译资产并验证它们是可用的。
我让服务器打印出一些值
- puts Rails.application.assets.find_asset('application.css').digest_path
- puts stylesheet_link_tag 'application'
它具有正确的资产价值,但 stylesheet_link_tag 生成了错误的链接。
[web0] application-2c5efa873b0d0254861e6a7ee25995dd.css
[web0] <link rel="stylesheet" media="screen" href="https://<something>.cloudfront.net/stylesheets/application.css" />
当我们在 Heroku 上运行时,显然有些不同,但配置文件的设置是相同的,gem 等也是如此。这是我们的 staging.rb 配置文件的相关部分
App::Application.configure do
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_files = true
config.static_cache_control = 'public, max-age=2592000'
# Compress JavaScripts and CSS.
# config.assets.css_compressor = :sass
config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(mangle: false)
config.assets.compile = false # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.digest = true # Generate digests for assets URLs.
config.assets.version = '2.0' # Version of your assets, change this if you want to expire all your assets.
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
config.action_mailer.asset_host = config.action_controller.asset_host = 'https://<something>.cloudfront.net'
end
我在网上搜索,但我发现的唯一建议是设置
config.assets.compile = true,确实解决了问题,但也会导致服务器在部署后尝试加载页面超时。
有人知道这里有什么问题吗?为什么要寻找非消化资产?
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 asset-pipeline