1

在我的用户模型中,我想在上传时调整图像大小。我将图像存储在亚马逊 s3 上。一切都很好,图像显示、上传、删除等,直到我尝试在块中添加after_assign方法。image_accessor

这是错误:

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

我已经按照在线教程进行操作,并仔细检查了所有内容。我认为这是 imagemagick 或 rmagick 的错误,但在重新安装后我不知所措。我的路径$ which convert是 /opt/local/bin/convert ,我很确定该路径显示出来是好的。

关于如何让流程正常工作的任何建议?我在 Snow Leopard、Ruby 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)
4

1 回答 1

2

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

于 2012-07-19T10:20:42.747 回答