Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: application.css not in asset pipeline

I know this is a old question but no answer is fixing my problem.

I'm new to Ruby on Rails and just created project with a PostgreSQL database just to be able to upload the project to Heroku.

When i start the rails server im getting the error "application.css is not present in the asset pipeline."

I'm using bootstrap 4 gem and this requires that you rename the applications.css to application.scss.

I dont know what is wrong.

I really tried every answer that is on stackoverflow without any success :(

Please help me, what am i doing wrong?

This is the error im getting: enter image description here

like image 204
Webbie Avatar asked Jun 15 '19 21:06

Webbie


2 Answers

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

like image 196
mutantkeyboard Avatar answered Sep 20 '22 19:09

mutantkeyboard


origin answer

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.

update

also, make sure all of these things:

  1. file exists: app/assets/stylesheets/application.css
  2. its content looks like:
/* ...
 *= require_self
 *= require_tree .
 */
  1. also check file app/assets/config/manifest.js,
//= link application.css
like image 44
Siwei Avatar answered Sep 17 '22 19:09

Siwei