在調試this problem的過程中,我試圖在生產模式下在本地運行我的應用程序,並且它不提供任何資產。另外,我還有一個在Heroku應用程序中啓用環境(與我的產品Heroku應用程序分開),它現在也顯示沒有任何資源的HTML。未在生產環境或臨時環境中投放資產的導軌
要調試,我:
- 殺死服務器
- 清除出TMP /緩存/資產
- 刪除公共/資產
- 運行
rake assets:precompile
- 啓動服務器
rails s -e production
- 訪問該頁面並打開Web檢查器,單擊application.css鏈接的展開箭頭時,它會顯示
Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
- 重新加載頁面不做任何事情。
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" %>
您能否展示您如何訪問資產?像'= stylesheet_link_tag「application」,:media =>「all」' – 2013-03-04 17:04:26
我已經更新了這個問題。 – railsuser400 2013-03-04 17:06:53
您使用的是什麼Rack中間件?切換到精簡需要我設置'config.assets.compile = true'而不是默認的'false' - 但如果我使用Passenger則不會。 – sameers 2015-12-10 20:04:57