2017-05-27 89 views
0

我在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 
+0

分享你的模型你上传/处理版本 –

回答

0

要输出的图像,你可以尝试使用image_tag @course.image.url(:thumb)uploader.thumb.url。如果您在图片上传后添加了拇指,则需要重新上传或测试其他@course对象。

没关系,文件名称不同,因为它已经是另一个文件了 - 你有你的原始文件并剪切。

+0

我用它们两个,它不调整大小 – RailsH

+0

你是什么意思“它不调整大小”?它显示原始尺寸?请尝试重新启动您的Rails服务器并上传新的图像以获得新课程实例。 – TiSer

+0

@railsh你尝试过吗? – TiSer