When assets are compiled, Sprockets digests each file's path and adds a hash to it, so for example, this:
example.com/assets/Image.png
is turned into this:
example.com/assets/Image-f8hs838fa1479fhsu1341d483nj4b9fa95f850h3n47d74a7cd81a22ljs8f3c3.png
To access an image or other file in Rails, one simply has to call its path, like this: <%= image_tag 'Image.png' %>
.
But what if you're in a position when you can't use erb? For example, in a CSS file, setting a background-image using a file's undigested path doesn't work, because the path doesn't actually exist on production, so something like background-image: url('../images/Image.png')
or background-image: url('/assets/Image.png')
lead to a missing image. Another example is writing an image into a text block. Trying to print this:
<% post.text = "text <img src='/assets/Image.png'/> more text" %>
<%= post.text.html_safe %>
will once again result in a missing image on production.
Is there a way to access files without the hash? Or is there a way to call the Rails method in situations like the two examples I gave? Assuming no concern for security.