2015-12-04 80 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