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
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.
rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With