0

My image is located at assets/images/logo.png and I can use it fine with Ruby/HAML's image tag. However, when creating an HTML page, <img src='/assets/logo.png'> can't find the image. When I go to the HAML created page and use Inspect Element, I find that the image is actually located under /assets/logo-<a bunch of numbers>.png and if I use that for my HTML page, it works fine. However, that number is different in development and in production. What is that number? And what should I use as image source in other HTML pages?

thisisdee
  • 878
  • 3
  • 16
  • 41
  • should you not be using the haml syntax to create your image? that way it will sort out that number no matter which environment you are in - [see this](http://stackoverflow.com/questions/10561121/how-to-add-an-image-to-the-contents-using-haml) – Pete Nov 25 '14 at 13:57

1 Answers1

1

that is called the fingerprints for assets in rails. Consider reading the guide: http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark

This is used to prevent caching problems: when you update the asset, but keep the old name, browsers may still show the old, cached image. But with the fingerprint the name will be different and the new image will always be delivered.

You should always use haml/erb asset helpers _asset_path 'logo.png'_ syntax referencing the assets in your code, so rails will take care on that fingerprints.

roman-roman
  • 2,746
  • 19
  • 27