I found this answer earlier, and we happily used find_asset in our application (Rails 3.2.16) until one day it started to bomb.
After some digging, it turns out that even in a production environment with precompilation enabled, the first call to find_asset will actually try to compile the asset that it is looking for, even if this asset has already been precompiled. As you can imagine, this is not good news - in our particular case, we pulled out the Compass library file into a stylesheet that worked in dev and during pre-compilation, but not in production, where Compass was not in the asset loading path.
In short, find_asset not a bulletproof way to determine if an asset is available for inclusion. You can read a bunch more about this in a problem that someone was trying to report about it, and which was subsequently closed as not a bug: https://github.com/sstephenson/sprockets/issues/411
The real way to determine if an asset exists, and which works both in compilation and precompilation modes, is demonstrated in hoops so that the file of the above problems needs to be skipped. Here's the diff for fixing it: https://github.com/fphilipe/premailer-rails/pull/55/files
I put it here in the hope that the other Googlers who find it will not fall into the same trap as me!
rusty Mar 21 '14 at 17:56 2014-03-21 17:56
source share