Rails does not load assets located in public directory in production

前端 未结 2 647
执念已碎
执念已碎 2020-12-24 13:44

Hello i have assets in public directory (because of simplicity)

in layout i load



        
相关标签:
2条回答
  • 2020-12-24 14:22

    Configuration changed for Rails 4 and 5.

    For Rails 4:

    config.serve_static_files = true
    

    For Rails 5:

    config.public_file_server.enabled = true
    
    0 讨论(0)
  • 2020-12-24 14:23

    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.

    0 讨论(0)
提交回复
热议问题