ruby-on-rails - how to access specific ActiveStorage image in multiple images
问题描述
I am using ActiveStorage for Ruby on Rails project. A post has many images and I want to use the one of images with headline. I am wondering how to access specific image in multiple images.
Current code is like this. I create hash(key: post ID, value: image) and access hash data in view. I can show the image but is there another better way to access specific image?
@posts.each do |p|
if p.post_images.present? && p.headline_image_id.present?
@headline_image_id.store(p.id, p.post_images.select {|image| image.blob_id == p.headline_image_id})
end
end
解决方案
推荐阅读
- r - 在 eventReactive 中使用反应条件
- r - 用选定的平均值和标准差缩放向量
- android - Firebase 谷歌登录失败
- c++ - 通过 intmax 有效划分 int
- elasticsearch - elasticsearch中文本数据类型的ignore_above
- javascript - 如何使用javascript在元素中显示图像?
- java - 如何在 Java 中将 JMSBytesMessage 转换为 TextMessage
- mongodb - 为什么 mongodb upsert 计数器不反映实际变化?
- javascript - 我无法正确创建别名
- python - 在python中读取和解释混合的二进制和文本文件