[英]Unable to display image using variant with ActiveStorage image_processing gem
目前,我正在開發Rails 5.2應用程序。 當我嘗試使用variant
在show.html.erb
模板中顯示個人資料的頭像時,它不起作用
<%= image_tag @profile.avatar.variant(resize_to_fit: [100, 100]) %>
我看不到圖片。
我在Gemfile中安裝了gem'image_processing gem 'image_processing', '~> 1.2'
。
同樣在application.rb
我添加了config.active_storage.variant_processor = :vips
但是,仍然在后端出現500錯誤:
Started GET "/rails/active_storage/representations/xxxx/steven.jpeg" for 127.0.0.1 at 2018-09-26 16:33:21 -0400
Processing by ActiveStorage::RepresentationsController#show as JPEG
Parameters: {"signed_blob_id"=>"xxxxxx", "variation_key"=>"xxxxxx", "filename"=>"steven"}
ActiveStorage::Blob Load (0.3ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
↳ /Users/stevenaguilar/.rvm/gems/ruby-2.2.2/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
Disk Storage (0.1ms) Checked if file exists at key: variants/7rnyyMpZaqXT4RBNtzDqPFqS/477efe2eb62003af0b5b40ec71c56de636f58f942964d830feeed4057b8718a6 (no)
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.3ms)
如果我編輯為<%= image_tag @profile.avatar %>
可以看到原始圖像。
這是Photo
模型:
class Profile < ApplicationRecord
belongs_to :user
has_one_attached :avatar
end
有什么建議么?
您使用的Rails版本是5.2
,該版本的ActiveStorage沒有variant_processor
選項。
resize_to_fit
是屬於image_processing
的選項。 您安裝了gem,但是處理器固定為mini_magick
。 參見: https : //github.com/rails/rails/blob/v5.2.3/activestorage/app/models/active_storage/variant.rb#L117
如果要保留5.2的版本,則應遵循mini_magick
提供的mini_magick
。 參見: https : //api.rubyonrails.org/classes/ActiveStorage/Variation.html
如果您喜歡使用image_processing
來享受方便的選擇,則應將Rails版本升級到> = 6。
嘗試這個:
<%= image_tag @profile.avatar.variant(resize: "100x100") %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.