Rails does not load assets located in public directory in production Rails does not load assets located in public directory in production ruby-on-rails ruby-on-rails

Rails does not load assets located in public directory in production


Configuration changed for Rails 4 and 5.

For Rails 4:

config.serve_static_files = true

For Rails 5:

config.public_file_server.enabled = true


This is because you have

  config.serve_static_assets = false

in your production.rb file.

From the Rails Configuration guide:

  • config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.

And like that guide suggests, you really shouldn't rely on serving assets from public/ via your Rails app, it is better to let the web server (e.g. Apache or Nginx) handle serving assets for performance.