Rails: application.css not in asset pipeline
Ok, first thing.
Do you have config.serve_static_files = true
set in your production.rb
file under config/environment
folder.
Since we run behind NGINX, in our case it looks like config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
Second thing. Did you do rails assets:precompile
before the uploading it to the server?
And the third thing is. Have you tried calling your file application.css.scss
, and redoing the rails assets:precompile
?
Last, and not least thing. How does your application.scss
file look like?
Did you remove all those *=
and used @import
instead for Bootstrap
It is nicely described in the documentation:
Import Bootstrap styles in app/assets/stylesheets/application.scss:
// Custom bootstrap variables must be set or imported before bootstrap. @import "bootstrap";
And then it says:
Make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead. If this file exists, it will be served instead of Sass, so rename it:
$ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss Then, remove all the *= require and *= require_tree statements from the Sass file. Instead, use @import to import Sass files.
Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins and variables.
Read more here
in my case, I forgot to install yarn command in my server.
so, please install "yarn" before running rails server. otherwise "assets:precompile" will do nothing and give no warning.
To give more clarity to mutantkeyboard's answer
I had this issue when deploying a Rails application as a docker image that would run in a docker container without a web server like Nginx.
Here's how I got it fixed:
This issue is primary caused in production when you do not want to serve your static files from the /public
folder using a web server like Nginx or Apache.
To serve files your static files from the /public
folder without using a web server like Nginx or Apache, do the following:
Ensure you precompile your assets using:
bundle exec rails assets:precompile
OR
rails assets:precompile
This will compile your assets into the /public
folder
Next, in your config/environments/production.rb
file, add the following:
Instead of this:
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
Use this:
config.public_file_server.enabled = true
This allows rails to serve the static files instead of a web server
Note: For improved performance it's best to serve the static files using a Web server like Apache or Nginx.
That's all.
I hope this helps