I have an external javascript plugin and there is a lot of code like this where the image src attribute is built dynamically.
$prod.append("<img class='fx_shadow' id='shd_" + i + "' + src='" + folderAssets + "/shadow_fx.png' />");
With rails 4.1+, I am precompiling the related images and assets that this external code provides and references above. Naturally, the images fail to load in production because using direct src attributes doesn't capture the fingerprint of the digested and precompiled image.
How do I call the asset_url
method (which does output the correct asset file name with the digest) properly from an external javascript file rather than a css file? (This javascript is not a restful template js.erb file, but rather, a js file included in the manifest.)
Also, is there an elegant way to approach and refactor this?
.js.erb
and then:$prod.append("<img class='fx_shadow' id='shd_" + i + "' + src='<%= asset_path('shadow_fx.png') %>' />");
– Surya Nov 3 '14 at 11:25$prod.append("<%= image_tag 'shadow_fx.png', :class => 'fx_shadow' %>");
– Surya Nov 3 '14 at 11:28