Rails not servicing assets in production or intermediate environments

In the process of debugging this problem, I tried to run the application locally and does not serve any assets. In addition, I have an intermediate environment in the Heroku application (separate from my Heroku application), which also now displays HTML without any assets.

To debug, I:

  • Kill the server
  • Clear tmp / cache / assets
  • Delete publication / assets
  • Run rake assets:precompile
  • Start the rails s -e production server
  • Go to the page and open the web inspector, and by clicking on the extension arrow for the application.css link, you will answer Reload the page to get source for: http://localhost:3000/assets/application-e1f3e0c864a153c7iu66f8772a886376.css
  • Reload 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 

The following is a link to the stylesheet and javascript in layout / application.html.erb:

 <%= stylesheet_link_tag "application", :media => "screen, handheld" %> <%= javascript_include_tag "application" %> 
+4
source share
2 answers

So the problem was that the memory store was set to config.cache_store = :dalli_store , which caused errors and set it to config.cache_store = :memory_store .

+6
source

This is some kind of hunch, but does not compile assets that should be set to true?

 config.assets.compile = true 

and I think you need to compile such assets as follows:

 rake assets:precompile RAILS_ENV='production' 
+6
source

Source: https://habr.com/ru/post/948177/


All Articles