2015-12-04 56 views
0

我有一个Rails 4.2应用程序,它在Heroku上使用预编译资产运行。我们正在尝试迁移到新平台(Aptible),但使用相同的设置,我们的应用不再正确获取资产。是的,我运行bundle exec rake assets:precompile预编译资产并验证它们可用。未在生产中使用消化资产的Rails

我有服务器打印出来几个值

- 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上运行,但配置文件被设置为相同的,因为是宝石等这是我们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,这不解决问题,而且还导致服务器超时尝试加载部署后的页面。

有人知道这里有什么问题吗?为什么要寻找非消化资产?

谢谢!

回答

1

您可能需要在部署后在生产环境中运行预编译任务。

我假设Heroku默认是这样做的。

这里有发现了几个例子:

https://gist.github.com/fancyremarker/9652688

+0

感谢您的想法,但我们已经在做,在我们的before_release任务,这里https://support.aptible.com/topics/建议paas/how-to-store-static-assets/ – notruthless

+0

我发现这个合理的支持文章是错误的,我确实需要在Dockerfile中执行precompile assets命令,而不是确保它发生在同一个容器内。 – notruthless