When I write this code to show image filename for the alt
:
<img class="card-img-top" alt="<%= store.main_image.filename %>" draggable="false" src="<%= my_store_url(store) %>" />
by using :
store.main_image.filename
for alt
, it doesn't show the actual filename, but numbers like this 1000043.jpg
in production environment.
But when I use it in development environment, it does show the actual filename.
When I write this code to show image filename for the alt
:
<img class="card-img-top" alt="<%= store.main_image.filename %>" draggable="false" src="<%= my_store_url(store) %>" />
by using :
store.main_image.filename
for alt
, it doesn't show the actual filename, but numbers like this 1000043.jpg
in production environment.
But when I use it in development environment, it does show the actual filename.
Share Improve this question asked Feb 5 at 9:55 John SallJohn Sall 1,1531 gold badge15 silver badges34 bronze badges1 Answer
Reset to default 1Development:
- In dev this is okay
Production:
- But in prod active Storage often generates a unique key for the file, and the filename you see (1000043.jpg) is likely an internal reference rather than the original filename. (for the uniqueness it will generate name like this).
<img class="card-img-top" alt="<%= store.main_image.blob.filename.to_s %>" draggable="false" src="<%= my_store_url(store) %>" />
store.main_image.blob.filename.to_s ensures you get the actual filename stored in Active Storage.