b_d
b_d

Reputation: 787

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

something along the lines where i can iterate through a list of Image objects and reassign the image file as a paperclip attachment. Thanks.

Upvotes: 2

Views: 882

Answers (1)

apneadiving
apneadiving

Reputation: 115541

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

Upvotes: 6

Related Questions