Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image assets not found after upgrading to Rails 3.1

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?

like image 680
bratsche Avatar asked Sep 20 '11 01:09

bratsche


1 Answers

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!

like image 195
Andrew Theis Avatar answered Sep 19 '22 07:09

Andrew Theis