Home#index中的ActiveStorage :: InvariableError [英] ActiveStorage::InvariableError in Home#index
问题描述
当前,我正在尝试在Rails 6中显示 .HEIC
图像.我正在使用
Currently I'm trying to display .HEIC
images in Rails 6. I'm using ActiveStorage ImageMagic to use variant to display jpg
. Basically I'm trying to use
mogrify -format jpg myimage.heic
在图像中显示 jpg
.
我将 Rails.application.config.active_storage.variant_processor
添加到application.rb中,以便能够使用该变体.但是,它似乎中断了以下行:
I added Rails.application.config.active_storage.variant_processor
into application.rb to be able to use the variant. However it seems to break in the following line:
<%= image_tag post.image.variant(format: 'jpg'), class: "card-home__img" %>
为什么不工作?
推荐答案
在调用 variable时,您只能在返回
. true
的图像上调用 variant
?
You can only call variant
on an image that returns true
when you call variable?
on it.
在内部, ActiveStorage
检查 ActiveStorage.variable_content_types
是否包含图像的类型.支持的默认值为:
Internally, ActiveStorage
checks if ActiveStorage.variable_content_types
contains your image's type. The default supported values are:
-
image/png
-
图像/gif
-
图像/jpg
-
image/jpeg
-
image/pjpeg
-
图像/tiff
-
图像/bmp
-
image/vnd.adobe.photoshop
-
image/vnd.microsoft.icon
-
图像/webp
image/png
image/gif
image/jpg
image/jpeg
image/pjpeg
image/tiff
image/bmp
image/vnd.adobe.photoshop
image/vnd.microsoft.icon
image/webp
因此,似乎当前不支持.HEIC图像.
So it seems that currently .HEIC images are not supported.
相反,您可以在将图像附加到模型或存储模型之前应用格式转换,这可能会解决您的用例.
You can instead apply a format transformation before attaching the image to a model or storing it, it might solve your use case.
这篇关于Home#index中的ActiveStorage :: InvariableError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!