I have a client who wants to bulk-upload photo files to her existing Ruby on Rails application that I developed. I’ve scratched together code and scripts to unzip a zip file and rename all included files sequentially:
photo0001.png, photo0002.png etc…
However, I’m stuck on how to write a model or method to go through and assign each photo to a new instance, as paperclip defines the following:
class Picture
has_attached_file :photo
So I’m looking for a way to do something like this:
for i in 1..5
Picture.create(:caption => "Test", :photo => "photo/photo000#{i}.png")
`rm photo/photo000#{i}.png`
end
I’m sure there’s more to it than that, but that’s the basic idea…
I have a rake task for uploading photos, the meat of it looks like this:
I don’t know if this helps, but it should hopefully point you in the right direction.