Rails不在生产或登台环境中提供资产

问题描述 投票:4回答:2

在调试此问题的过程中,我尝试在本地生产模式下运行我的应用程序,它不提供任何资产。 另外,我在Heroku应用程序中有一个临时环境(与我的生产Heroku应用程序分开),它现在也显示没有任何资产的HTML。

为了调试,我:

  1. 杀死服务器
  2. 清除tmp / cache / assets
  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

以下是我在layout / application.html.erb中链接样式表和javascript的方法

<%= stylesheet_link_tag "application", :media => "screen, handheld" %>
<%= javascript_include_tag "application" %>
ruby-on-rails-3 asset-pipeline
2个回答
7
投票

这是一种猜测,但不编译资产需要设置为true?

config.assets.compile = true

我认为你需要像这样编译资产:

rake assets:precompile RAILS_ENV='production'

7
投票

所以问题是内存存储设置为config.cache_store = :dalli_store导致错误并将其设置为config.cache_store = :memory_store解决了它。

© www.soinside.com 2019 - 2024. All rights reserved.