【发布时间】:2014-04-29 13:33:40
【问题描述】:
我在 heroku 上运行一个 rails 4.0 应用程序,在我的一生中,我无法使用我在 assets_host 中设置的主机获取我的资产 URL。
我相信我的云端设置很好,因为我可以用我的云端 url 替换我的任何资产 url,并且文件从 heroku 中提取并缓存在云端。
所以https://xxxxxxxxxxxx.cloudfront.net/assets/application-xxxxxxxx.js 正在正确缓存https://myapp.com/assets/application-xxxxxxxxx.js。
问题似乎是我的资产助手(例如 javascript_include_tag)从未使用 staging.rb 中的资产主机设置。
我在加载页面时看到的只是我的所有 js 和 css 文件都来自 https://myapp.com/assets/
我的暂存设置如下所示:
# 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 = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
#config.assets.digest = false
#config.assets.initialize_on_precompile = true
config.static_cache_control = "public, max-age=31536000"
# user Amazon Cloudfront for asset hosting
config.action_controller.asset_host = "https://xxxxxxxxxxxx.cloudfront.net"
是否有某种神奇的配置设置组合让我不知所措?
【问题讨论】:
-
您是否尝试过从asset_host 值中删除
https://? -
感谢 Rich 的建议,但我已经发现了问题并在下面进行了描述。
-
很好 - 很高兴你修复了它!我为你投票:)
-
我也建议不要使用
staging.rbdevcenter.heroku.com/articles/… -
感谢@Schneems 的提示 - 这听起来很明智且易于实施。
标签: ruby-on-rails heroku assets amazon-cloudfront