在调试此问题的过程中,我尝试在本地以生产模式运行我的应用程序,但它没有提供任何资产。此外,我在 Heroku 应用程序(与我的生产 Heroku 应用程序分开)中有一个暂存环境,它现在也显示没有任何资产的 HTML。
要调试,我:
- 杀死服务器
- 清除 tmp/cache/assets
- 删除公共/资产
- 跑
rake assets:precompile
- 启动服务器
rails s -e production
- 访问该页面并打开网络检查器,当单击 application.css 链接的展开箭头时,它会显示
Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
- 重新加载页面什么都不做。
生产.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
暂存.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
应用程序.rb:
config.assets.enabled = true
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
下面是我如何在layout/application.html.erb中链接样式表和 javascript :
<%= stylesheet_link_tag "application", :media => "screen, handheld" %>
<%= javascript_include_tag "application" %>