views:

46

answers:

2

I'm happily using attachment_fu to handle file uploads and thumbnail creation. However, for some (but not all!) cases I would like to suppress the creation of thumbnails.

How would I hack attachment_fu to do this?

Specifics: I have a traditional attachment_fu model

class Pic < ActiveRecord::Base
  has_attachment :content_type => :image, :storage => :s3, :resize_to => '200x600>',
                 :thumbnails => { :thumb48 => [48,48], 
                                  :thumb32 => [32,32], 
                                  :thumb22 => [22,22] }
  validates_as_attachment
end

The user specifies the file to be uploaded in a form using a file input, and submits the form to an action where the pic is created using

@pic = Pic.new(params[:pic])

In certain cases I'd like to be able to do something like

@pic = Pic.new(params[:pic], {:generate_thumbnails => false})

and prevent the thumbnails from being generated.

+2  A: 

interesting question.

have you thought about just not displaying the thumbnails for certain pics? or is storage a concern?

another option would be to create two models - one called Pic which doesn't define any thumbnails and then one called PicWithThumbs, which extends the Pic class, and does define thumbnails.

Then in your controller you could do an 'if' statement that checked the params for a value called 'create_thumbs' (boolean) - if :create_thumbs is true, then create an instance of PicWithThumb, else create a Pic

I know, it smells a little, and I'm a bit of a noob, so feel free to shoot me down. I'm interested in seeing what the best solution is though...

stephenmurdoch
Totally reasonable suggestion, but it doesn't work for my particular application -- I'm trying to supply the thumbnails from another source for certain pics rather than creating them first using the default method and then having to overwrite them.
brahn
A: 

I'm not sure about attachment fu, but in paperclip you can stop thumbnail generation by returning false in before_post_process, in attachment fu perhaps you could do a similar thing in the process_attachment callback?

Andrew Nesbitt
Ooh, good idea. I will give that a try!
brahn