开发者

How to make existing images into paperclip images?

Before using paperclip with rails, I wrote my own upload script with which I uploaded a batch of images and assigned to their respective objects. But now i need to switch all the images to be paperclip friendly.

Is there a way to pass images to paperclip without using a form?

Image.all.each do |image|
  image[:file] = image.filename
  image.save
end

som开发者_运维百科ething along the lines where i can iterate through a list of Image objects and reassign the image file as a paperclip attachment. Thanks.


Given file is the name of your paperclip object, I'd do something like:

Image.all.each do |image|
 image.file = File.open("#{Rails.root}/path_to_images/#{image.filename}")
 image.save
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜