Rails not serving assets in production or staging environments

萝らか妹 提交于 2020-01-11 09:27:11

问题


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.

To debug, I:

  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

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" %>

回答1:


This is sort of a guess, but doesn't compile assets need to be set to true?

config.assets.compile = true

and i think you need to compile the assets like this:

rake assets:precompile RAILS_ENV='production'



回答2:


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.



来源:https://stackoverflow.com/questions/15206789/rails-not-serving-assets-in-production-or-staging-environments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!