views:

738

answers:

3

I've added 2000 pictures to my images table and I'm using the Paperclip plugin to create thumbs. I'm wondering if there's a way to go through the database and add another :styles element.

For example, when I added the images I had the following in my model:

has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }

However, now I want to add a :large attribute and have it applied to every image that's already in my table. Something like:

has_attached_file :image, :styles => { :large => "800x800>", :medium => "300x300>", :thumb => "100x100>" }

Is this possible? Or would I have to re-add all 2000 pictures?

+2  A: 
rake paperclip:refresh:thumbnails
mculp
A: 

I'm also having problems with this. I get:

$: rake paperclip:refresh:thumbnails RAILS_ENV=production CLASS=Photo
(in /home/public_html/XXXXX/releases/20091108211450)
rake aborted!
undefined method `read' for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/paperclip-2.1.2/lib/paperclip/attachment.rb:163:in `reprocess!'
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:45
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:26:in `for_all_attachments'
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:24:in `each'
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:24:in `for_all_attachments'
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:22:in `each'
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:22:in `for_all_attachments'
/home/avishai/public_html/XXXXX/releases/20091108211450/lib/tasks/paperclip.rake:44

Does anyone know what's going on?

Thanks!

Avishai
+1  A: 

If Paperclip is installed as a plugin, you can do this:

rake paperclip:refresh:thumbnails CLASS=Screenshot

where Screenshot is the name of the class with the attachment.

If it's installed as a gem, do this inside script/console:

Screenshot.all.each {|s| s.image.reprocess! }

replacing Screenshot with the appropriate class name

Jonathon Horsman