Reputation: 19247
My app runs fine in development mode.
When I run in production mode using RAILS_ENV=production rails s
none of my .css or .js files get loaded. (I did precompile assets, using RAILS_ENV=production bundle exec rake assets:precompile
.)
The webrick log shows:
ActionController::RoutingError (No route matches [GET] "/assets/application-a73ce43be7bf75953cd0c60b2b4a7eb0.js"):
and
ActionController::RoutingError (No route matches [GET] "/assets/application-986dd79830088c416c1632c12999ec69.css"):
The files were compiled (according to the log\production.log file) and my public/assets directory does show those files with and without the fingerprint:
ls public/assets
application-986dd79830088c416c1632c12999ec69.css
application-986dd79830088c416c1632c12999ec69.css.gz
application-a73ce43be7bf75953cd0c60b2b4a7eb0.js
application-a73ce43be7bf75953cd0c60b2b4a7eb0.js.gz
application.css
application.css.gz
application.js
application.js.gz
Upvotes: 29
Views: 7407
Reputation: 124419
Rails doesn't serve static assets in production mode by default. If you want to disable this and serve the static assets, update your config/environments/production.rb
file with this:
config.serve_static_assets = true
The reasoning behind Rails' default configuration is that it assumes you'll be running behind a standard web server in production mode (Apache, Nginx, etc.) which will then proxy the requests to your Rails app. Since the assets are precompiled, Apache/Nginx/etc. can directly serve them without needing to talk to your Rails processes.
Upvotes: 47