Carrierwave - 处理图像时出错

时间:2011-02-23 22:14:54

标签: ruby sinatra mongoid carrierwave

问题是mongoids save!操作引发了以下错误。

Mongoid::Errors::Validations: Validation failed - Img failed to be processed.
~/.rvm/gems/ruby-1.8.7-p249/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb:234:in `fail_validate!'
~/.rvm/gems/ruby-1.8.7-p249/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb:75:in `save!'
./app.rb:29:in `POST /upload'

设置主要是以下内容:

require "sinatra"     # 1.1.2
require "mongoid"     # 2.0.0.beta.19
require "rmagick"     # 2.12.2
require "carrierwave" # 0.5.1
require "carrierwave/orm/mongoid"
require 'carrierwave/processing/rmagick'
....


Mongoid.database = Mongo::Connection.new('somehost', 1234).db('test')

class Uploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  storage :file

  def store_dir
    "uploads"
  end

 process :resize_to_fit => [80, 80]
end


class Image
  include Mongoid::Document

  mount_uploader :img, Uploader
end


....

post '/upload' do
  @img = Image.new
  @img.img = params[:file]
  @img.save!
  redirect '/'
end

故障是处理中的某个地方:

process :resize_to_fit => [80, 80]

如果我删除此行。一切都按预期工作。

1 个答案:

答案 0 :(得分:7)

确定。我没有足够深入地跟踪这些痕迹: 问题是ImageMagick中缺少jpeg-delegate。 所以自然处理jpeg文件失败了。

解决方案是从源代码重新安装ImageMagick。

当Mongoid抛出一个从carrierwave调用的错误时,它仍然是非常不透明的,因为它从Imageagagick触发的RMagick中获取错误。

静止。回顾展很明显: - )