簡體   English   中英

Rails 5.2:Active Storage Variants service_url 在瀏覽器中拋出“沒有這樣的鍵”錯誤

[英]Rails 5.2: Active Storage Variants service_url throwing "no such key" error in browser

我正在使用 rails 5.2、active_storage 和 image_magic 以及 minimagick 來創建不同大小的變體,我使用以下代碼來生成變體:

attachment.variant(combine_options: {
                          resize: "#{size}x#{size}^",
                          extent: "#{size}x#{size}",
                          gravity: 'center',
                          quality: 95 }
                        ).service_url

使用service_url方法生成的 url 成功創建變體並加載到瀏覽器中,但在生產中拋出以下錯誤:

在此處輸入圖像描述

如果我不創建變體,它工作得很好。

您需要對變體調用#processed以便Rails 處理並上傳它。 軌道 v7.0:

has_one_attached :image do |attachable|
  attachable.variant :thumb, resize_to_limit: [100, 100]
end

def thumb_url
  image.variant(:thumb).processed.url if image.attached?
end

文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM