technoweenie / attachment_fu

Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
http://weblog.techno-weenie.net
MIT License
1.02k stars 339 forks source link

Size restrictions are not properly applied to separate thumbnail class. #6

Open eviltwin opened 15 years ago

eviltwin commented 15 years ago

I have two classes, one which manages the "child" images and one for the "parent" images.

In the parent image class I have: class Photo < ActiveRecord::Base has_attachment :content_type => :image, :storage => :file_system, :size => 1..5.megabytes, :thumbnails => { :thumb => 'c100x100' }, :thumbnail_class => ChildPhoto, :path_prefix => "Photos"

  validates_as_attachment
end

And in the child class: class ChildPhoto < ActiveRecord::Base has_attachment :content_type => :image, :storage => :file_system, :path_prefix => "Photos",

  validates_as_attachment
end

I've removed the :belongs_to stuff because mine is quite funky and gets in the way of reading :)

Anyways, this is code for a friend's photography portfolio and so obviously the images can be quite large when first uploaded. The issue, though, is that I left the size parameter as the default for the child class as I figured thumbnails wouldn't be very large at all. However, the image size is checked before the resize operation and so the child class throws its toys out of the pram because it has an image that is larger than it is expecting. Is this expected behavior? The solution, obviously, is to also apply the :size option to the ChildImage class, but this feels wrong to me...