Rails 4: assets not loading in production
In /config/environments/production.rb
I had to add this:
Rails.application.config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb )
The .js was getting precompiled already, but I added it anyway. The .css and .css.erb apparently don't happen automatically. The ^[^_]
excludes partials from being compiled -- it's a regexp.
It's a little frustrating that the docs clearly state that asset pipeline IS enabled by default but doesn't clarify the fact that only applies to javascripts.
All assets are not loading in production envirnoment rails 5
In production.rb
set
config.public_file_server.enabled = true
config.assets.compile = true
Then run the server like this
RAILS_ENV=production rails assets:precompile
RAILS_ENV=production rails server
Some assets not loading in an old Rails 3-2-stable app
The asset pipeline concatenates your assets to only generate and serve specified files, 'application.js', 'application.css' and images/fonts by default.
If you are explicitly including other css/js files in your application via the javascript_include_tag
or stylesheet_link_tag
helpers, you'll need to add those files manually to the pipeline via the config.assets.precompile +=
setting in your application.rb
or an initializer.
Currently, those files should already be included within your application
manifest via the require_tree .
directive. So, the styles might be being applied right now too. If that's the case, you can just remove your code that adds the individual stylesheets separately to get rid of the 404s.
Still not sure how the app is working fine on heroku, maybe you have some heroku config that's enabling serving the static assets.
Rails 4.1.6 Asset pipeline not loading assets and javascript in production
So it turned out to be a simple solution. I was using docker to push to production and needed to add this line to my Dockerfile
RUN rake assets:precompile
This precompiles the assets and adds the fingerprint so they can be served in production. Cheers!
Related Topics
How to Find Where a Method Is Defined At Runtime
Ruby Block and Unparenthesized Arguments
How to Pick Randomly from an Array
How to Sum Array of Numbers in Ruby
How to Convert a String Object into a Hash Object
Difference Between Include and Extend in Ruby
Ruby: How to Post a File Via Http as Multipart/Form-Data
Do..End VS Curly Braces For Blocks in Ruby
How to Get a Random Number in Ruby
"Bin/Rails: No Such File or Directory" W/ Ruby 2 & Rails 4 on Heroku
Regular Expressions With Validations in Ror 4
How Does the Magic Comment ( # Encoding: Utf-8 ) in Ruby Work