Posted by ant
October 18th, 2007
Filed in Rails
Update – This has now been fixed and included in Release 3007 Hurrah!!!!
I’ve found a bug in Rick Olsons attachment_fu plugin. If you create image attachments and using a different model for the thumbnails, eg.
class Image < ActiveRecord::Base has_many :thumbnails, :dependent => :destroy has_attachment :content_type => :image, :thumbnail_class => ‘Thumbnail’, :thumbnails => { :sidebar => “x200” }, :storage => :file_system validates_as_attachment end
class Thumbnail < ActiveRecord::Base belongs_to :image has_attachment :content_type => :image, :storage => :file_system end
If you have an image with an id of 1 and a thumbnail with an id of 1 then when you try to destroy image (id=1) the code will go into an infinite loop as the destroy_thumbnails function will think the thumbnail itself is has thumbnais and try to recursively delete itself until the stack level gets too deep.
def thumbnailable?
image? && respond_to?(:parent_id)
end
def destroy_thumbnails
self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
end
To make sure only the base image is considered to have thumbnails. The thumbnailable? function can be changed to:-
def thumbnailable?
image? && respond_to?(:parent_id) && parent_id.nil?
end
The attached patch updates this and implements a test to ensure it works.
Blog uses Mephisto
Design from OSWD
by dreamLogic

Leave a Reply ☆