【问题标题】:Rails 5: Active Storage Link Adds ?local=enRails 5:活动存储链接添加 ?local=en
【发布时间】:2018-10-06 06:30:21
【问题描述】:

我有一个产品模型,它通过 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 添加到图片链接?

【问题讨论】:

    标签: ruby-on-rails rails-activestorage ruby-on-rails-5.2


    【解决方案1】:

    原来问题不在于语言环境,而是通过以下方式解决的其他问题:https://evilmartians.com/chronicles/rails-5-2-active-storage-and-beyond

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 2017-11-26
      • 2020-11-04
      • 2022-12-08
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多