Rails App Not Serving Assets in Production Environment

前端 未结 8 1993
佛祖请我去吃肉
佛祖请我去吃肉 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:02

    As previously noted config.serve_static_assets is deprecated and replaced by config.serve_static_files. If one examines config/environments/production.rb for Rails-4.2 then one finds this:

      # Disable serving static files from the `/public` folder by default since
      # Apache or NGINX already handles this.
      config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
    

    The implication being that setting and exporting (in BASH) the environment variable export RAILS_SERVE_STATIC_FILES="to any value whatsoever" in a session prior to running rails s -e production will give the desired result when testing locally and also will avoid having to remember to recode production.rb before pushing to the production host.

提交回复
热议问题