Ruby on rails 通过命令行连接导轨/回形针

Ruby on rails 通过命令行连接导轨/回形针,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我的服务器上的文件夹中有一堆jpeg文件,我正试图通过一个rake任务将它们附加到相应的属性实例 property.rb具有以下代码: has_attached_file :temp_photo, :styles => PropertyImage::STYLES, :url => "/assets/:class/:attachment/:id_partition/:style_:basename.:extension", :path => "#{Ra

我的服务器上的文件夹中有一堆jpeg文件,我正试图通过一个rake任务将它们附加到相应的
属性
实例

property.rb
具有以下代码:

  has_attached_file :temp_photo,
    :styles => PropertyImage::STYLES,
    :url => "/assets/:class/:attachment/:id_partition/:style_:basename.:extension",
    :path => "#{Rails.root}/public/assets/:class/:attachment/:id_partition/:style_:basename.:extension"
我在其他型号上使用回形针,没有任何问题,但我尝试以下操作时遇到问题:

p = Property.find(id)
file = File.open(temp_file_path)
p.temp_photo = file
p.save

# => false

file.close
p.errors

# => "/tmp/stream20110524-1126-1cunv0y-0.jpg is not recognized by the 'identify' command."
该文件确实存在,我已尝试更改权限。重新启动服务器没有帮助。问题似乎在于使用命令行,因为正常的表单/HTTP方法工作得很好。这只是一个临时设置,所以我正在寻找一种工作方式,将一批文件导入我的rails应用程序回形针模型


有什么建议吗?

看看这个不,我已经试过了,似乎没什么区别。正如我所说,当我在apache上添加图像时,它工作得很好——问题出在rake任务/控制台中。你确定图像是正确的吗?如果手动调用
identify/tmp/stream2011….
,会发生什么情况?也许一些更新的版本会适合您-我可以毫无问题地使用回形针2.4.0导入文件。请参阅。to_suym应该是。to_sym
path = 'target_file_path'
attach_name = 'temp_photo'

p = Property.find(id)
attach = Paperclip::Attachment.new(attach_name, p, p.class.attachment_definitions[attach_name.to_suym])

file = File.open(path) 
attach.assign file
attach.save

file.close