It took me a while to figure this out and I don't see any wiki pages
for attachment_fu so I figure I would just post this here.
I didn't like the way attachment_fu by default creates directories
under a given directory for a specific class e.g.
After a while you end up with ton of directories under the item_image
directory. Instead I wanted the images to be grouped by the item
object which has_many item_images. You can do that by adding the
following two methods to the item_image object.
# Make sure the related item is associated to the thumbnail child
before_thumbnail_saved do |record, thumbnail|
thumbnail.item = record.item
def full_filename(thumbnail = nil)
# Just to be sure the ID gets set
raise "Missing Item ID" if item_id.nil?
file_system_path = (thumbnail ? thumbnail_class :
File.join(RAILS_ROOT, file_system_path, item_id.to_s,
and in your Item class you add a condition since it makes it easier to
iterate over the images and for example call the image helpers
:conditions => "parent_id is null"
Now all the directories will be grouped by the item_id.