I've upgraded an app to Rails 3.1, and everything is setup and working correctly except that an image_tag isn't finding the image. I've moved all my images from public/images to app/assets/images. The browser requests an image at http://localhost:3000/assets/foobar.png but it just shows up as a broken image in Chrome. Opening it in a separate tab says "No route matches [GET] "/assets/foobar.png".
I feel like I'm just missing some setting somewhere, but I haven't been able to find out what it is yet. Any suggestions?
One of the biggest things they don't mention in the Assets Pipeline Guide is to remove the leading /images/ part of the path. So for example this:
<%= image_tag "/images/about/header.png" %>
Would have to be changed to this:
<%= image_tag "about/header.png" %>
Same goes for CSS files. So this:
background-image: url("/images/alliance/header_background.png");
Would change to:
background-image: image-url("alliance/header_background.png");
Note that when using the asset pipeline never include the leading slash. Also if you use the above line of code in your CSS file, be sure to add .scss to the file (so application.css would become application.css.scss).
Hope this saves you some headache!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With