In your config/environments/production.rb
file, set:
config.serve_static_assets = false
(currently it's set to true)
config.assets.compile = true
(currently it's set to false)
This should solve your problem.
Let me explain what I am asking you to do.
- By setting
config.serve_static_assets = false
, we are telling rails server, don't addActionDispatch::Static
middleware, which is used to serve static assets.
Why not?
That's because in production environment, you are expected to run your application server (like puma) behind a web server (like Apache/Nginx), which is designed to serve static files (including assets) directly, without bothering to send the request to rails application server.
Since, you are not using any web server, we are turning it off.
- By setting
config.assets.compile = true
, we are telling rails to compile the requested asset at runtime. i.e. Look for the requested asset inapp/assets
,vendor/assets
,lib/assets
and serve it if found from any of these locations.
By default, config.assets.compile
is true
in development, false
in production environment. Since, we are not using web server to serve static assets, we are asking rails to live compile our assets.
For further details refer to the asset pipeline documentation.