通过命令行安装滑轨/回形针

问题描述

| 我的服务器上的文件夹中有一堆jpeg文件,我正尝试通过rake任务将它们附加到其对应的ѭ0实例上。
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应用回形针模型的可行方法。 有什么建议么?     

解决方法

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