Question

I have a Rails 3.2 Project deployed to Heroku and using Asset Sync that has grown to a point where there are so many assets that Precompiling them on Heroku is too slow. So I'm using:

$ rake assets:precompile

… to compile the assets locally (with Asset Sync pushing them to an S3 bucket). Obviously this creates an assets folder in my public folder containing all the precompiled assets.

Now when I push to Heroku, it sees that I've precompiled my assets and skips precompilation, making my deploy much faster.

The problem comes when I go back to developing locally. Now that the assets are precompiled, Rails uses those assets and doesn't pick up changes I make to my local files. The obvious thing to do is to delete the assets, but this means that every time I push I need to first re-precompile the assets which is time-consuming.

So how can I tell Rails to ignore any assets in the public directory and use my unprecompiled local files whilst in the development environment.

Was it helpful?

Solution

Change / set the assets_prefix in config/environments/development.rb, like suggested in the RailsGuides:

config.assets.prefix = "/dev-assets"

From now on Rails checks this folder (public/dev-assets) in dev-mode for any precompiled assets instead of the default location (public/assets) - and uses your unprecompiled local files, if dev-assets is empty:

Since rake assets:precompile runs in production mode by default (same as RAILS_ENV=production rake assets:precompile), compiled assets are still written to the default-location public/assets, but never to public/dev-assets - this way your dev-env won't be affected at all ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top