50

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?

Slobodan Kovacevic
  • 6,848
  • 3
  • 29
  • 33
  • sorry, not exactly helping your problem, but how do you see the Rails.application.config.assets.paths ? – Martin Jul 03 '11 at 12:30
  • 1
    @martin: you can see it in console – Slobodan Kovacevic Jul 03 '11 at 15:29
  • This might be a stupid question, but are your jqueryui assets in the images directory? Mine are in the image directory, and then in their own subdirectory to preserve the CSS paths jqueryui's theme maker generates. – Slick23 Jul 06 '11 at 13:05
  • Having the same problem, feels like a bug to me. – kim3er Sep 09 '11 at 13:37
  • 4
    I'm sure you have tried it already, but just in case: I was having the same problem even after moving the assets to the right location, modifying jQuery UI CSS image paths and making sure everything was correct. Restarting the dev server solved it in the end. Seems Sprockets needs to restart to get new assets. – tomtastico Sep 11 '11 at 16:05
  • +1 to @TomásArribas - the CSS file has `images/` as part of its path. removing that was the cure for me – grumpit Mar 14 '13 at 15:27

4 Answers4

79

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.

Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
  • Using Pow (and powder gem) I just tried a 'powder restart' with no luck. Then I tried 'powder down' and 'powder up' and finally Rails.application.config.assets.paths included vendor/assets/images. – Chris Mar 31 '12 at 14:09
  • If you're using pow, just `touch tmp/restart.txt` in your console to restart the individual app. No need to bring the whole server down. – Adrian Macneil Jul 19 '13 at 11:36
22

If you are using a jQuery UI Theme Roller theme then the problem might be that in the jquery-ui css file the images are referenced within a sub folder 'images'.

I.e. you either have to put your images in a folder './app/assets/images/images' or you have to edit the jquery-ui css file and remove the 'images/' folder prefix.

idmean
  • 14,540
  • 9
  • 54
  • 83
woelfle
  • 557
  • 1
  • 7
  • 23
  • 8
    It's somewhat confusing that you might see `GET http://example.com/assets/images/darrowleft.gif 404 (Not Found)` in a javascript console and you have that image in `vendor/assets/images`. However, you*should* see `http://example.com/assets/darrowleft.gif` for the URL. To see `http://example.com/assets/images/darrowleft.gif` you have to put that image in `vendor/assets/images/images` as @woelfle explained. Doing so will save you the hassle of having to modify paths in vendored CSS files. – George Anderson Dec 02 '11 at 16:18
  • Putting the images in yet another folder called images seems weird, but worked for me on rails 3.1.3. Thanks! – counterbeing Dec 06 '11 at 07:43
  • Thank you, George, that was the missing piece of the puzzle for me! – Sprachprofi Apr 10 '12 at 11:43
9

The asset pipeline is described in this rails guide by Ryan Bigg (draft status at the moment).

http://ryanbigg.com/guides/asset_pipeline.html and http://ryanbigg.com/2011/06/sprocket-asset-tags-internals/ for the references.

According to this, your example should work.

Extract:

Assets can be placed inside an application in one of three locations: app/assets, lib/assets or vendor/assets.

app/assets is for assets that are owned by the application, such as custom images, javascript files or stylesheets.

lib/assets is for your own libraries’ code that doesn’t really fit into the scope of the application or those libraries which are shared across applications.

vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins.

Any subdirectory that exists within these three locations will be added to the search path for Sprockets (visible by calling Rails.application.config.assets.paths in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it’s processed by Sprockets and then served up.

I have tested with an example in my app and the same syntax as yours works. Maybe you have a typo in the name of your asset.

For Martin: search path for Sprockets is visible by calling Rails.application.config.assets.paths in a console.

Community
  • 1
  • 1
vincent jacquel
  • 5,107
  • 2
  • 17
  • 18
2

Maybe you should create another folder in /assets/images. You make a name 'images' and then you just copy all jquery-ui image and paste on folder 'images' that you create before. Hopefully this will help you.

daynRails
  • 21
  • 2