我无法在 RoR 中使用 Carrierwave/Minimagick gem 实现简单的图像上传器。
我正在尝试在上传时将文件转换为灰度,但出现错误。这是代码:
image_uploader.rb:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Process files as they are uploaded:
process :convert_to_grayscale
def convert_to_grayscale
manipulate! do |img|
img.quantize(256, Magick::GRAYColorspace)
img = yield(img) if block_given?
img
end
end
当我尝试上传文件时,出现以下错误:
uninitialized constant ImageUploader::Magick
app/uploaders/image_uploader.rb:36:in `block in convert_to_grayscale'
app/uploaders/image_uploader.rb:35:in `convert_to_grayscale'
我相信这是由于 Magick::GRAYColorspace 枚举常量。任何想法为什么这不起作用?