Rails App Not Serving Assets in Production Environment

前端 未结 8 1998
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 01:29

My app works fine when run in development environment. In production (rails server -e production), the browser can\'t access the css and js files and on the con

8条回答
  •  没有蜡笔的小新
    2020-12-01 02:05

    I think to Rails 4.x you have to precompile assets to production or use config.assets.compile even both if needed.

    The default Rails behavior for production environment is to "Do not fallback to assets pipeline if a precompiled asset is missed." So, don't. Use to not compi

    config.assets.compile = false
    

    If you use this option you don't need to use:

    config.serve_static_files = true
    

    Because if the asset wasn't precompiled, Rails will compile before serve request.

    But if you do precompile the assets before production you don't needs config.assets.compile = true, but you need config.serve_static_files = true to Rails serve requests if you don't have http_server to serve the precompiled assets.

    The setting config.serve_static_assets is deprecated.

    DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly.
    

    I hope this answer help you(reader) to understand whats really happens

提交回复
热议问题