Rails assets not precompiling, css looks different in production

前端 未结 1 628
忘了有多久
忘了有多久 2020-12-31 08:10

My rails app in dev mode works and looks exactly as I want it to, but in production it looks different on chrome and safari, in safari the logo images loads but not the font

相关标签:
1条回答
  • 2020-12-31 08:28

    In your config/environments/production.rb file, set:

    config.serve_static_assets = false (currently it's set to true)

    config.assets.compile = true (currently it's set to false)

    This should solve your problem.

    Let me explain what I am asking you to do.

    • By setting config.serve_static_assets = false, we are telling rails server, don't add ActionDispatch::Static middleware, which is used to serve static assets.

    Why not?

    That's because in production environment, you are expected to run your application server (like puma) behind a web server (like Apache/Nginx), which is designed to serve static files (including assets) directly, without bothering to send the request to rails application server.

    Since, you are not using any web server, we are turning it off.

    • By setting config.assets.compile = true, we are telling rails to compile the requested asset at runtime. i.e. Look for the requested asset in app/assets, vendor/assets, lib/assets and serve it if found from any of these locations.

    By default, config.assets.compile is true in development, false in production environment. Since, we are not using web server to serve static assets, we are asking rails to live compile our assets.

    For further details refer to the asset pipeline documentation.

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