Rails无法在生产或暂存环境中提供资产 [英] Rails not serving assets in production or staging environments
问题描述
在调试此问题的过程中,我尝试在本地以生产模式运行我的应用程序,并且该应用程序无法使用任何资产.另外,我在Heroku应用程序(与生产的Heroku应用程序分开)中有一个 staging 环境,该环境现在也显示了没有任何资产的HTML.
In the process of debugging this problem, I have tried to run my application in production mode locally and it doesn't serve up any assets. Additionally, I have a staging environment in a Heroku application (separate from my production Heroku application) which is also now displaying the HTML without any assets.
要调试,我:
- 杀死服务器
- 清除tmp/cache/assets
- 删除公共/资产
- 运行
rake assets:precompile
- 启动服务器
rails s -e production
- 访问该页面并打开Web检查器,然后单击应用程序的展开箭头.css链接显示
Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
- 重新加载页面无济于事.
- Kill the server
- Clear out tmp/cache/assets
- Delete public/assets
- Run
rake assets:precompile
- Start up the server
rails s -e production
- Visit the page and open up web inspector and when clicking the expand arrow for the application.css link it says
Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
- Reloading the page does nothing.
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
下面是我如何在 layout/application.html.erb 中链接样式表和javascript:
Below is how I link the stylesheet and javascript in layout/application.html.erb:
<%= stylesheet_link_tag "application", :media => "screen, handheld" %>
<%= javascript_include_tag "application" %>
推荐答案
所以问题是内存存储设置为config.cache_store = :dalli_store
,这会导致错误,并将其设置为config.cache_store = :memory_store
可以解决该问题.
So the problem was that the memory store was set to config.cache_store = :dalli_store
which was causing errors and setting it to config.cache_store = :memory_store
resolved it.
这篇关于Rails无法在生产或暂存环境中提供资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!