2013-05-02 61 views
0

我開始玩Rails4,無法讓資產管道正常工作。我的網站在我的暫存環境中加載得很好,除了我的CSS或js沒有被合併或縮小爲Rails 3之外。是否有某些版本之間發生更改?Rails 4 Asset Pipeline沒有合併或縮小資產

這裏是我的staging.rb環境文件:

MyApp::Application.configure do 
    config.cache_classes = true 
    config.eager_load = true 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 
    config.serve_static_assets = false 
    config.assets.js_compressor = :uglifier 
    config.assets.compile = false 
    config.assets.digest = true 
    config.assets.version = '1.0' 
    config.log_level = :info 
    config.cache_store = :dalli_store 
    config.i18n.fallbacks = true 
    config.active_support.deprecation = :notify 
    config.log_formatter = ::Logger::Formatter.new 
end 

回答

2

這是通過在我身邊的問題引起的。不知怎的,我把我的服務器,以「發展」在我的環境變量,所以它從來沒有運行這個臨時文件...

關於@ frandroid的回答,你不希望設置

config.assets.compile = true 

,因爲它將懶惰地編譯生產資產。您應該確保在將文件推送到服務器期間或在手之前完全編譯它們,以確保最佳性能。

這是我的最後staging.rb文件:

MyApp::Application.configure do 
    config.cache_classes = true 
    config.eager_load = true 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 
    config.serve_static_assets = false 
    config.assets.js_compressor = :uglifier 
    config.assets.compile = false 
    config.assets.digest = true 
    config.assets.version = '1.0' 
    config.log_level = :info 
    config.cache_store = :dalli_store, ENV["MEMCACHIER_SERVERS"].split(","), 
        {:username => ENV["MEMCACHIER_USERNAME"], 
        :password => ENV["MEMCACHIER_PASSWORD"]} 
    config.i18n.fallbacks = true 
    config.active_support.deprecation = :notify 
    config.log_formatter = ::Logger::Formatter.new 
end 
+0

我有同樣的問題。我可以從資產管道中顯示圖像的唯一方法是更改​​'config.assets.compile = true'。這真的很奇怪。如果我啓動一個新的香草應用程序並將圖像添加到'/ assets/images/image.png',則只有在設置了此變量時才能在生產中查看它。否則,即使使用預編譯的資產,它也不會顯示。有什麼想法嗎? – kobaltz 2013-07-10 02:18:05

+0

@kobaltz:我認爲你需要使用scss image_url('image.jpg')'而不需要添加'/ assets/images /'。圖片文件夾中只有圖片名稱。如果在圖像中有一個文件夾,那麼'image_url('new/image.jpg')'和僅用於查看頁面'image_tag'將有助於'config.assets.compile = false' – 2014-11-06 05:58:17

相關問題