2012-07-17 24 views
1

在我的用户模型中,我想调整上传时的图像大小。我将图像存储在亚马逊S3上。一切都很好,图像显示,上传,删除等,直到我试图在image_accessor块中添加after_assign方法。过程imagemagick函数不能与蜻蜓::处理器一起使用

以下是错误:

None of the functions registered with Dragonfly::Processor were able to deal with the 
method call thumb 

我跟着网上教程,并仔细检查了一切。我认为这是一个与imagemagick或rmagick错误,但重新安装两个Im在亏损。我的$ which convert的路径是/ opt/local/bin/convert,我非常确定路径显示出来很好。

关于如何让流程工作的任何建议?我雪豹,红宝石1.9.3运行和Rails 3.2.5


参考:

这里是我的用户模型:

class User < ActiveRecord::Base 

    image_accessor :avatar do 
     storage_path{ |file| "#{self.id}/avatar/#{rand(1000)}.#{file.format}" } 
     after_assign{ |a| a.thumb!('300x300#') } 
    end 

    ... 

    attr_accessible :name, :location, :avatar, :retained_avatar, 
    # Used by Devise 
    :email, :password, :password_confirmation, :remember_me, :confirmed_at 

    validates_size_of  :avatar, maximum: 5.megabytes, allow_nil: true 
    validates_property :format, of: :avatar, 
    in: [ :jpg, :png, :gif ], case_sensitive: false, allow_nil: true, 
    message: "Only .jpg, .png and .gif file formats are supported." 

end 

这里是我的蜻蜓初始化

require 'dragonfly' 

app = Dragonfly[:images] 

app.configure_with(:imagemagick) 
app.configure_with(:rails) 

app.datastore = Dragonfly::DataStorage::S3DataStore.new 

app.datastore.configure do |c| 
    c.bucket_name = ENV['S3_BUCKET'] 
    c.access_key_id = ENV['S3_KEY'] 
    c.secret_access_key = ENV['S3_SECRET'] 
    c.url_scheme = 'https' 
end 

app.define_macro(ActiveRecord::Base, :image_accessor) 

回答

2

如果您的文件名为:photo,那么其after_assign应该是after_assign { |a| self.photo = a.thumb('300x300#) }

+0

编辑你的答案:如果你的文件被调用:photo,它的after_assign {| a | self.photo = a.thumb('300x300#)}我会给你一个赏金。 – AJcodez 2012-07-20 07:48:40