Rails Application Doesn't Load CSS/Js/Images in Production-Environment

rails application doesn't load css/js/images in production-environment

make the following change in config/production.rb

change:

config.serve_static_assets = false

to:

config.serve_static_assets = true

That will fix it, I guarantee

Rails 4 - Background Image Appears in Localhost but not in production

Your problem with almost certainly be to do with rake assets:precompile & your production environment

A good test will be to Right-Click > View Source on your production app and click on the CSS file where your background image is called. If your problem is your CSS is calling url("background-image.png") & when you click onto the file, it doesn't show, the solution is to use SCSS to precompile the assets dynamically


Precompiling The Assets With SCSS

We had the problem where you couldn't access the image files in the CSS, and found it was because the CSS was only referencing static url() locations; and in precompile, our app was calling images "backgroun-image-234234nsdfasfdjasdfk2jij234ij32i.png"

The way to fix that is to use SCSS to create dynamic links to the assets; allowing your app to put the correct path to the images, etc. Here is some live code:

#application.css.scss (yes, you need to rename it)
@import 'layout/body'

#app/assets/stylesheets/layout/body.css.scss
body {
background: asset_url('background-image.png')
}

If you do this, and then when you push to production, you perform these commands, it should work:

rake assets:precompile RAILS_ENV=production

CSS files, JavaScript files and images not rendering in production server

Try this:

config.serve_static_assets = true

in your rails_app_path/config/environments/production.rb.

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.

CSS is not loading in Rails 4.2.5 | development environment

Move your css files from public directory to app/assets/stylesheets/ directory, it will resolved your problem.

By *= require_tree . line of code in application.css includes all css files within app/assets/stylesheets/ directory.

replace your below lines
from

<%= stylesheet_link_tag    'assets/stylesheets/application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'assets/javascripts/application', 'data-turbolinks-track' => true %>

to

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

it will works fine

Rails 6.1.1 doesn't load the webpacker created CSS files in production mode

We had the same issue with the match? method missing for ActionDispatch::FileHandler

We traced it back to: https://github.com/romanbsd/heroku-deflater/issues/54

Removing the heroku-deflater gem fixed it for us

Rails Production server stylesheet not loading

Use RAILS_ENV=production rake assets:precompile. RAILS_ENV=production specifies the environment in which you run your rake tasks.



Related Topics



Leave a reply



Submit