I’m trying to update this code to work with the released 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’s the best way temporarily change the sprockets output directory?
Edit: Also I’d like to be able to clean the assets in my custom output directory 🙂
You can use
config.assets.prefix, but this will still put the assets in the public directory (see here for the rake task, which joins thepublic_pathand the prefix).In your case, this should work:
I had to specify the manifest path because of the weird load order of the sprockets railtie. Without doing it, it gets stuck at
public/assets, which doesn’t exist and blows up the rake task. YMMV.Side note: I tried this in the development environment at first, but the
config.assets.prefixrefused to change. I suspect puttingconfig.assets.enabledtotruewould have fixed this, but I haven’t got around to testing it yet.As a bonus, the
assets:cleanworks perfectly with this solution (you can see it for yourself in the rake task)