version :thumb
を搬送波によって提供されたクラスで使用しようとしました。しかし、version :thumb
クラスを使用した場合、画像にエラーがあり、URLにthumb
が追加され、画像が破損します。Carrierwaveを使用した画像のサイズ変更
<img src="/uploads/course/image/2/thumb_OX50XkO.jpg" alt="Thumb ox50xko">
オリジナル画像のリンクには、URLにthumb
という単語がありません。
EDIT:
モデル:
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
アップローダ:あなたはimage_tag @course.image.url(:thumb)
やuploader.thumb.url
を使用しようとすることができ
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
バージョンをアップロード/処理しているモデルを共有しています –