我有一个产品模型,该模型通过Active Storage具有许多图像
class Product < ApplicationRecord
has_many_attached :images
end
“我的产品/展示”视图显示的第一张图片是显示所有其他图片的模态的链接:
- if @product.images.present?
= link_to image_tag(@product.images.first, class: "img-fluid"), "#", data: {toggle: "modal", target: "#images"}
/ or
= link_to image_tag(url_for(@product.images.first)), "#", class: "img-fluid", data: {toggle: "modal", target: "#images"}
#images.modal
.modal-dialog
.modal-content
.modal-body
.carousel-inner
.carousel-item.active
= image_tag = @product.images.first, class: 'd-block w-100'
- @product.images.drop(1).each do |image|
.carousel-item
= image_tag image, class: 'd-block w-100'
a.carousel-control-prev data-slide="prev" href="#image_controls" role="button"
span.carousel-control-prev-icon
a.carousel-control-next data-slide="next" href="#image_controls" role="button"
span.carousel-control-next-icon
几分钟后效果很好。但是以某种方式,几分钟后?locale=en
便从Active Storage添加到图像链接中,因此该图像不再显示。
<img src="/rails/active_storage/blobs/longstring/image_file.jpg">
成为
<img src="/rails/active_storage/blobs/longstring/image_file.jpg?locale=en">
我的路线文件:
scope "(:locale)", locale: /en|ja/ do
resources :products
如何防止Rails将locale=en
添加到图像链接?
答案 0 :(得分:0)
事实证明问题不在于语言环境,而是由以下内容解决的:https://evilmartians.com/chronicles/rails-5-2-active-storage-and-beyond