Rails无法在生产或暂存环境中提供资产 [英] Rails not serving assets in production or staging environments

查看:145
本文介绍了Rails无法在生产或暂存环境中提供资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试此问题的过程中,我尝试在本地以生产模式运行我的应用程序,并且该应用程序无法使用任何资产.另外,我在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.

要调试,我:

  1. 杀死服务器
  2. 清除tmp/cache/assets
  3. 删除公共/资产
  4. 运行rake assets:precompile
  5. 启动服务器rails s -e production
  6. 访问该页面并打开Web检查器,然后单击应用程序的展开箭头.css链接显示Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
  7. 重新加载页面无济于事.
  1. Kill the server
  2. Clear out tmp/cache/assets
  3. Delete public/assets
  4. Run rake assets:precompile
  5. Start up the server rails s -e production
  6. 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
  7. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆