最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - image filename doesn't show the name of the image but it only shows numbers in rails7 - Stack Overflow

programmeradmin9浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

Development:

  • 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.

发布评论

评论列表(0)

  1. 暂无评论