2013-03-04 122 views
4

在調試this problem的過程中,我試圖在生產模式下在本地運行我的應用程序,並且它不提供任何資產。另外,我還有一個在Heroku應用程序中啓用環境(與我的產品Heroku應用程序分開),它現在也顯示沒有任何資源的HTML。未在生產環境或臨時環境中投放資產的導軌

要調試,我:

  1. 殺死服務器
  2. 清除出TMP /緩存/資產
  3. 刪除公共/資產
  4. 運行rake assets:precompile
  5. 啓動服務器rails s -e production
  6. 訪問該頁面並打開Web檢查器,單擊application.css鏈接的展開箭頭時,它會顯示Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
  7. 重新加載頁面不做任何事情。

Production.rb

config.cache_classes = true 
config.consider_all_requests_local  = false 
config.action_controller.perform_caching = true 
config.serve_static_assets = true 
config.static_cache_control = "public, max-age=3600" 
config.assets.compress = false 
config.assets.compile = false 
config.assets.digest = true 

Staging.rb

config.cache_classes = true 
config.consider_all_requests_local  = false 
config.action_controller.perform_caching = true 
config.serve_static_assets = true 
config.static_cache_control = "public, max-age=3600" 
config.assets.compress = false 
config.assets.compile = false 
config.assets.digest = true 

application.rb中

config.assets.enabled = true 
config.assets.version = '1.0' 
config.assets.initialize_on_precompile = false 

下面是如何我佈局鏈接樣式表和javascript/application.html.erb

<%= stylesheet_link_tag "application", :media => "screen, handheld" %> 
<%= javascript_include_tag "application" %> 
+1

您能否展示您如何訪問資產?像'= stylesheet_link_tag「application」,:media =>「all」' – 2013-03-04 17:04:26

+0

我已經更新了這個問題。 – railsuser400 2013-03-04 17:06:53

+0

您使用的是什麼Rack中間件?切換到精簡需要我設置'config.assets.compile = true'而不是默認的'false' - 但如果我使用Passenger則不會。 – sameers 2015-12-10 20:04:57

回答

6

所以問題是,內存存儲設置爲config.cache_store = :dalli_store這是導致錯誤並將其設置爲config.cache_store = :memory_store解決它。

+3

由於某種原因,似乎不會有任何關係。這怎麼可能? – courtsimas 2013-05-28 21:26:27

+1

@CourtS:在開發/生產中緩存資源時,鏈輪將[使用默認緩存存儲](http://guides.rubyonrails.org/asset_pipeline.html#assets-cache-store)。它默認爲文件存儲。 – James 2013-10-07 20:06:46

6

這是不大不小的猜測,但不編譯資產需要被設置爲true?

config.assets.compile = true 

,我認爲你需要編譯的資產是這樣的:

rake assets:precompile RAILS_ENV='production' 
+3

錯誤,'config.assets.compile = true'管道中資產的所有請求都由鏈輪直接處理。另外,指定環境並沒有什麼不同。 – railsuser400 2013-03-04 17:19:03

+0

您是否嘗試按照我的建議預先編譯資產?或者根據這個問題http://stackoverflow.com/questions/7340635/images-and-assets-not-working-in-my-production-server-on-rails-3-1-0,你可以嘗試設置' config.serve_static_assets = false'。 – Catfish 2013-03-04 17:21:44

+1

是的。我也改變了'config。serve_static_assets = false「,並且web檢查器中資產的摘要url與public/assets中文件的摘要url相匹配,但它仍然說'get http:localhost:3000/assets/application-e1f3e0c864a153c75866f8772a056376.css 404(not found)'。我也重新啓動了服務器並強制刷新瀏覽器。 – railsuser400 2013-03-04 17:35:19