问题
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:
- 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
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