Search code examples
cssruby-on-railsruby-on-rails-6webpacker

Can't load assets ressources (css + js) in production with Rails 6


When I start my application in production mode the assets (css + js) don't load correctly.

I get in browser's console net::ERR_ABORTED 404 (Not Found) or in Rails log ActionController::RoutingError (No route matches [GET] "/packs/js/application-51bdb73d26ac893c3407.js"):

I made rake assets:precompile and also turned config.assets.compile = true in environments/production.rb but same result

For the production mode I used the same app and the same directory I just add -e production as argument to the rails server command


Solution

  • Seems like you should set RAILS_SERVE_STATIC_FILES environment variable to true

    Suggestion is based on this issue comment I found while resolving same trouble

    This only affects configuration at config/environments/production.rb:

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