5

save!问题是在 mongoids操作中引发的以下错误。

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]

如果我删除这条线。一切都按预期工作。

4

1 回答 1

7

行。我没有深入跟踪跟踪:问题是 ImageMagick 中缺少 jpeg-delegate。所以自然地处理 jpeg 文件失败了。

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

当 Mongoid 抛出一个从载波调用的错误时,它仍然非常不透明,因为它从由 ImageMagick 触发的 RMagick 获得错误。

仍然。回想起来,这很明显:-)

于 2011-02-26T01:52:30.990 回答