4

我在使用带有 sinatra 和 mongoid 的回形针时遇到问题。当我上传时显示以下错误:


Paperclip::AdapterRegistry::NoHandlerError - No handler found for {"tempfile"=>#, "filename"=>"image-[Converted].jpg", "content_type"=>"image/jpeg", "size"=>35222}:

在模型中,我离开了:


class User
  include Mongoid::Document
  include Mongoid::Paperclip

  has_mongoid_attached_file :avatar,
    :path           => ':attachment/:id/:style.:extension',
    :default_url => '/images/missing_portrait_:style.jpg',
    :styles => {
      :original => '1920x1680>',
      :small    => '100x100#',
      :medium   => '250x250',
      :large    => '500x500>'
    }
end

并且路由/上传如下:

post '/upload' do
  User.create! ::avatar => to_paperclip(params[:file])
end

def to_paperclip(image)
  paperclip = {}
  paperclip['tempfile'] = image[:tempfile]
  paperclip['filename'] = image[:filename]
  paperclip['content_type'] = image[:type]
  paperclip['size'] = image[:tempfile].size
  paperclip  
end

我该如何解决这个问题?

4

2 回答 2

0

我没有找到回形针的任何解决方案,但我最终使用了载波,它可以满足我的需要

于 2012-07-14T20:08:35.837 回答
0

这对我有用

user = User.new()
user.avatar  = params[:avatar][:tempfile]
user.avatar_file_name = params[:avatar][:filename]
于 2013-09-26T14:39:09.797 回答