Search code examples
ruby-on-rails-3.1asset-pipeline

Why is the Asset Pipeline re-compiling compiled assets, creating redundantly nested paths?


When I deploy my app to the production environment (using capistrano), I have been getting an error during asset pre-compilation:

  * executing `deploy:assets:precompile'
  * executing "cd /home/ubuntu/projects/Marketplace-web/releases/20130124162353 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["server_name"]
    [server_name] executing command
*** [err :: server_name] rake aborted!
*** [err :: server_name] File name too long - /home/ubuntu/projects/Marketplace-web/releases/20130124162353/public/assets/assets/assets/assets/assets/assets/assets/assets/assets/assets/assets/assets/assets/widgets/jquery.jcarousel-d505e569ed1040e0b45bc33e0e49f117.js-26b4b41e4a45cb353ba7e39510893ace-93b194138c96579222ca08f9651946a7-43eca25d0cc511b37176bc58d8575e1a-1b97916c47bfa22545013b3751cb59e4-d9043106773924d12596e08b349f00dc-b7b7aa9bf440ca19896b1103d7651728-c40c1f2b8b11e6de163fefea9db6778c.gz+

I found a comment on http://railscasts.com/episodes/335-deploying-to-a-vps?view=comments , saying the issue can be solved by removing this from my config/application.rb:

config.assets.paths << "#{Rails.root}/public"

I removed it, and the task stopped re-compiling my pre-compiled, static assets in the public/assets folder, but my question is: Why was it doing that in the first place? Isn't that config line intended to tell Rails where to find my other, non-compiled, static assets? Why would it be trying to compile assets in the config.assets.paths array? Don't I need that line so Rails knows where to find my static assets?

Am I doing it all wrong? Where should I be putting my non-compiled, static assets and how should I tell Rails where to find them?


Solution

  • Check the Rails Assets Configuration Documentation:

    • config.assets.paths contains the paths which are used to look for assets. Appending paths to this configuration option will cause those paths to be used in the search for assets.

    Do not add the output directory to the array of input directories. Otherwise, the output of the previous assets-compilation run will be included as yet another input into the next assets-compilation run.

    Your compilable assets should typically be in app/assets if you wrote them or vendor/assets if you didn't. Why not put jquery.carousel.js into vendor/assets/javascripts/?