Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 4 asset pipeline vendor assets images are not being precompiled

I'm using rails 4 & ruby 1.9.3 for my application and fancybox2-rails gem, but there's a general problem with asset pipeline. If I run rake task for precompile, then everything is fine except for images in vendor/assets/images and ../gems/ruby-1.9.3-p327/gems/fancybox2-rails-0.2.1/vendor/assets/images. Images from these two folders are not being precompiled and eventually I have a problem with dead links to non-existing images. Any suggestions?

like image 800
banesto Avatar asked Jan 07 '13 11:01

banesto


People also ask

How do you Precompile an asset?

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.

How do you Precompile in rails?

This method is responsible for saving assets to disk, and is pretty self-explanatory. Run rake assets:precompile from the command-line from the root of your Rails application. Look at the public/assets directory and you'll see the assets of your Rails application. Our interest at this point is rails.

What does rake assets Clean do?

The clean it removes the old versions of the precompiled assets while leaving the new assets in place. Show activity on this post. rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.


2 Answers

It seems like images are included by default only from app/assets folder. So the solution is to add this line to config/application.rb

config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) 
like image 72
banesto Avatar answered Sep 21 '22 15:09

banesto


It sounds Sporker can't autoload images from vendor/assets/images.

2.2 Asset Organization Pipeline 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 and CSS frameworks

From the description come from guides.rubyonrails.org, I don't think they ignored vendor/assets/images with no intention.

So I just added the follow line:

#config/application.rb config.assets.paths << Rails.root.join("vendor", "assets", "images") 

And, I solved my problem. I hope this will work for you.

like image 40
rocLv Avatar answered Sep 21 '22 15:09

rocLv