ruby-on-rails - Rails 5:活动存储链接添加 ?local=en
问题描述
我有一个产品模型,它通过 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
到图像链接?
解决方案
事实证明问题不在于语言环境,而是通过以下方式解决了其他问题:https ://evilmartians.com/chronicles/rails-5-2-active-storage-and-beyond
推荐阅读
- java - 单例 Java 类可以有静态常量变量吗?声纳棉绒错误
- dart - 绘制从远程服务器下载的图像
- python-3.x - 如何在python中的高阶函数中更改父函数的参数
- java - 如果发生 SurefireBooterForkException,如何构建失败?
- css - Spring Boot + Thymeleaf css 不适用于模板
- reactjs - React,componentWillReceive lifeCycle Hook 未被调用(在传递道具时)
- python - 如何正确设置 STANFORD_MODELS VARIABLE?
- sql - 如何在 sql server(或 asp.net)中创建或生成此模式以供参考 ID
- google-search-console - 为什么我的“发现当前未编入索引”链接的数量增加了?
- python - 如何确定使用 Selenium 和 Python 在网页上查找和打开所有配置文件的确切 xpath 是什么?