1

我的Rails應用程序中有一個神祕的問題,我無法修復。Rails預編譯資產 - 無法在本地訪問預編譯的文件

問題是,我想要預編譯我的CSS和JavaScript,並在本地運行臨時環境中的服務器,以在部署到服務器之前檢查一切是否正常。

我運行此命令預編譯的文件:

rake assets:precompile RAILS_ENV=staging 

要開始登臺環境中的服務器運行此命令:

rails s -e staging 

的文件被成功預編譯,並放在公共/ assets文件夾,但無法在瀏覽器中加載,也無法從瀏覽器手動訪問這些文件。

我staging.rb環境文件看起來像這樣:

# Code is not reloaded between requests 
    config.cache_classes = true 

    # 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 = false 
    config.static_cache_control = "public, max-age=2592000" 
    config.action_controller.perform_caching = true 

    # Compress JavaScripts and CSS 
    config.assets.compress = true 
    config.assets.debug = true 

    # Don't fallback to assets pipeline if a precompiled asset is missed 
    config.assets.compile = false 

    # Generate digests for assets URLs 
    config.assets.digest = true 
    config.assets.initialize_on_precompile = true 

    # Use a different cache store in production 
    #config.cache_store = :dalli_store, 'localhost:11211' 


    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 
    config.assets.precompile += %w(.svg .eot .woff .ttf) 

在使用紅寶石以下版本,扶手:。

的Ruby 1.9.3 電壓軌v 3.2.14

回答

0

通過註釋行解決了問題:

config.serve_static_assets = false 
+2

請記住'rm -rf public/assets'在測試之後,否則您的開發服務器將加載舊的預編譯文件並忽略最近的代碼更改 – AlexChaffee