sprockets-rails
sprockets-rails copied to clipboard
image_path throwing Encoding::InvalidByteSequenceError due to bad javascript asset
TL;DR: A javascript file had invalid encoding and was causing image_path("image.png") to throw an Encoding::InvalidByteSequenceError. That shouldn't be the case, right?
I spent all day yesterday trying to debug why an image would be throwing this error. I tried various things to no avail, but today, I figured it out. At some point yesterday, I found a gist in a comment on this seemingly related issue. When I ran it, it gave me the offending JS file, but in my mind, that was something that had no bearing on the problem at hand. Clearly I was mistaken because today, as soon as I fixed that javascript file encoding with iconv, everything was fixed.
I narrowed the issue down to lib/sprockets/railtie.rb:251 before I stopped.
# Expose the app precompiled asset check to the view
self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path }