How to temporarily change the output path when recompiling assets, Sprockets / Rails pipeline 3.1.0

I am trying to update this code to work with the release of Rails 3.1.0:

# temporarily set the static assets location from public/assets to our spec directory ::Rails.application.assets.static_root = Rails.root.join("spec/javascripts/generated/assets") ::Rake.application['assets:clean'].invoke ::Rake.application['assets:precompile'].invoke 

Now that Sprockets :: Environment # static_root has been removed, what is the best way to temporarily change the sprockets output directory?

Edit: I would also like to be able to clear assets in my custom output directory :)

+6
source share
1 answer

You can use config.assets.prefix , but that will put the assets into a shared directory anyway (see here for the rake task, which combines public_path and the prefix).

In your case, this should work:

 Rails.application.config.assets.prefix = "../spec/javascripts/generated/assets" Rails.application.config.assets.manifest = File.join(Rails.public_path, config.assets.prefix) 

I had to indicate the manifest path due to the strange loading order of railtie stars. Without it, it gets stuck in public/assets , which does not exist and explodes the rake task. YMMV.

Side note: I tried this first in the development environment, but config.assets.prefix refused to change. I suspect that setting config.assets.enabled to true would fix this, but I have not had time to test it yet.

As a bonus, assets:clean works great with this solution (you can see it for yourself in the rake task )

+1
source

Source: https://habr.com/ru/post/896338/


All Articles