Rails App Not Serving Assets in Production Environment

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

    Check for a file like this:

    public/assets/.sprockets-manifest-3f7771d777ceb581d754e4fad88aa69c.json
    

    If you are pushing precompiled assets to a production server there is a chance that you are preventing hidden 'dot' files being pushed and this essential file won't make it into production.

    In my environment I need to precompile assets in an integration environment and push these to production so that there is no need to compile the assets on the production machine. I was erroneously blocking all hidden files from being pushed to production machine.

    To see if this answer works for you, check your generated HTML source in a browser from the production server to see if the assets path has been generated. If you see your script tag like this:

    
    

    check the src attribute. It should start with /assets/javascript. In this case it starts with /javascript which indicates Rails does not think any of the assets have been precompiled.

    I corrected this by updating my push to production (currently rsync), ensuring I push the .sprockets-manifest* file after precompiling on my integration server.

    Also, I use standalone Passenger as my integration test server, rather than Webrick, since it handles more realistic serving of static files.

提交回复
热议问题