在使用带有rails的paperclip之前,我编写了自己的上传脚本,我上传了一批图像并分配给各自的对象。但现在我需要将所有图像切换为回形针友好。
有没有办法在不使用表格的情况下将图像传递给回形针?
Image.all.each do |image|
image[:file] = image.filename
image.save
end
我可以遍历图像对象列表并将图像文件重新指定为回形针附件的行。感谢。
答案 0 :(得分:6)
鉴于file
是您的回形针对象的名称,我会做类似的事情:
Image.all.each do |image|
image.file = File.open("#{Rails.root}/path_to_images/#{image.filename}")
image.save
end