Reputation: 641
I just prepped my production server running Ubuntu 17.04, Apache2, Passenger, latest Ruby and Rails. When I browse my site, images used in CSS as background images do not load:
.firstrow {
background-image: url("backdrop2.png");
}
Error: http://server.lan/assets/backdrop2.png
I guess I have to use a more FQDN in CSS to fetch the image, but how come it works in dev? And what path should I use in CSS? I should also mention that I use SASS.
Upvotes: 2
Views: 1375
Reputation: 6026
You should use the image-url helper. If you are using Sass, you can replace your code with this:
.firstrow { background-image: image-url("backdrop2.png"); }
This of course assumes your image is in one of Rails' image assets search paths. By default, the Rails asset pipeline will search for your images in:
app/assets/images
lib/assets/images
vendor/assets/images
Also, make sure your deployment script runs rake assets:precompile RAILS_ENV=production
on your production server. Many do automatically, but not all.
Upvotes: 3
Reputation: 10025
The asset path used should be more dynamic to support both the enviroments.
body {
background: asset_url('background-image.png')
}
Try running rake assets:precompile RAILS_ENV=production
, in production environment as default assets(eg. images) are searched in public/assets folder.
Open firebug and check the path of image reference when the DOM element containing the image path loads up in page, also refer the logs to check the final path accessed and relate with the missing assets.
Upvotes: 0