Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 serving images from vendor/assets/images

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?

like image 755
Slobodan Kovacevic Avatar asked Jul 03 '11 09:07

Slobodan Kovacevic


People also ask

How do you Precompile rails assets?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What is Require_tree?

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.

What is assets Precompile?

rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .

What are rails Sprockets?

Sprockets is a crucial Ruby library that is used to serve and compile web assets. However, in Rails 7.0 the library becomes an optional dependency unless the application needs to use Sprockets. In such situations, the sprockets-rails gem will have to be added to the Gemfile .


1 Answers

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.

like image 158
Adrian Macneil Avatar answered Sep 21 '22 08:09

Adrian Macneil