我在CarrierWave提供的類中嘗試使用version :thumb
。但是,當我使用version :thumb
類時,圖像有錯誤,它在url中添加thumb
,破壞圖像。使用Carrierwave調整圖像大小
<img src="/uploads/course/image/2/thumb_OX50XkO.jpg" alt="Thumb ox50xko">
原始圖片鏈接在url中沒有thumb
這個詞。
編輯:
型號:
class Course < ApplicationRecord
has_many :course_categories
has_many :categories, :through => :course_categories
has_many :course_locations
has_many :locations, :through => :course_locations
mount_uploader :image, ImageUploader
end
者:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process resize_to_fit: [50, 50]
end
end
分享你的模型你上傳/處理版本 –