Application.CSS Not Being Served as an Asset

Rails: application.css not in asset pipeline

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

RoR App: The asset 'application.css' is not present in the asset pipeline after moving to production server

You can confirm your app/assets/stylesheets folder it should have application.css file and you will have to precompile assets in production environment before go/start server in production environment.
You can precompile assets using

RAILS_ENV=production rails assets:precompile

If it still does not work then you can try the config.assets.compile option to true in production.rb so it will do live compilation. Although it should be false in production environment as it impact on performance.

config.assets.compile = true

rails - application.css asset not found in production mode

Rails by default doesn't serve assets under public. See your production.rb:

  config.serve_static_assets = true

Change that to true and you're good to go. (Note: you don't want that to be true in production, remember to change it back before deploying!)

See Configuring Rails Applications for details.

In rails 6, in the default production.rb there should be a line

config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

So run your server with

RAILS_SERVE_STATIC_FILES=true rails server -e production

or set config.public_file_server.enabled=true in production.rb. See answers below for rails 4 and 5.

CSS file is not being applied

That means your server is not responding to requests for this css file with the appropriate MIME type. You can demonstrate that by requesting the CSS file and viewing the raw response (in your browser's developer tools, or via cURL, for example). What you want to see is:

text/css

But, given the error, what you will see is text/plain

According to Buffalo documentation:

By default the asset pipeline is configured to use .scss files, with /assets/css/application.scss as the main entry point. This, of course, can be changed.

I suggest you adopt the default scheme and use SCSS, and use the Buffalo asset helper:

stylesheetTag - This helper will generate a style tag for the requested CSS file. Example: <%= stylesheetTag("application.css") %> would return something like <link href="/assets/application.bd76587ded82386f388f.css" media="screen" rel="stylesheet" />

but if you don't wish to do that you could look into alternative configurations for serving CSS files with Buffalo, or into getting around Buffalo and serving CSS files without it.

Css changes are not being applied in rails app

So I have find out the reason and it was because I have run the command of assets precompile which I shouldn't have to run as rails was doing it already for me may be due to configuration of my project or may it is its default behavior.

To solve this problem I have to delete my projects folder from my system and clone it again and things got normal again.

And now I never ever going to run assets precompile command again /p>


Related Topics



Leave a reply



Submit