在我的用户模型中,我希望在上传时调整图像的大小。我将图片存储在亚马逊的s3上。一切都很好,图像显示、上传、删除等等,直到我尝试将after_assign方法添加到image_accessor块中。
这里是错误:
None of the functions registered with Dragonfly::Processor were able to deal with the
method call thumb我已经在网上学习了教程,并且仔细检查了所有的内容。我认为这是一个与映像或rmagick错误,但在重新安装后,我感到不知所措。对于$ which convert,我的路径是/opt/local/bin/转换,我很确定这条路径显示得很好。
对如何使流程工作有任何建议吗?我正在运行雪豹,Ruby1.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)发布于 2012-07-19 10:20:42
如果您的文件名为:photo,那么它的after_assign应该是after_assign { |a| self.photo = a.thumb('300x300#) }
https://stackoverflow.com/questions/11518280
复制相似问题