Rails 3.1 serving images from vendor/assets/images

Slobodan Kovacevic picture Slobodan Kovacevic · Jul 3, 2011 · Viewed 30.3k times · Source

I am trying to put some external images (used by a jQuery plugin) to vendor/assets/images in my Rails 3.1 app. Problem is that when I try something like:

<%= image_tag "ui-bg_flat_75_ffffff_40x100.png" %>

I get an error:

No route matches [GET] "/assets/ui-bg_flat_75_ffffff_40x100.png"

I checked my Rails.application.config.assets.paths and it list these dirs:

..../app/assets/images
..../app/assets/javascripts
..../app/assets/stylesheets
..../vendor/assets/images
..../vendor/assets/stylesheets
..../.rvm/gems/ruby-1.9.2-p180@mygems/gems/jquery-rails-1.0.9/vendor/assets/javascripts

As you can see /vendor/assets/images is listed there. If I put my image to app/assets/images everything works.

I thought that new asset pipeline was supposed to go through all assets dirs and serve requested file wherever it finds it.

Does anyone knows what's the problem here?

Answer

Adrian Macneil picture Adrian Macneil · Sep 20, 2011

I had to restart my rails server after creating the vendor/assets/images directory. Before this, I was seeing the same error as you ("No route matches [GET]").

My guess is that the rails server does not check these directories if they did not exist when it was first started. When you open a rails console to diagnose the issue, you get a new instance of rails which knows about the directory, which only adds to the confusion.