# Attachment\_fu File System Storage Change - Update?

**URL:** <https://www.ruby-forum.com/t/attachment-fu-file-system-storage-change-update/91277>\
**Category:** Rails\
**Created:** [April 6, 2007, 6:32am UTC](https://www.ruby-forum.com/t/attachment-fu-file-system-storage-change-update/91277 "2007-04-06T06:32:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hunter\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bc79bd/32.png) [@hunter\_h](https://www.ruby-forum.com/u/hunter_h)\
**Post date:** [April 6, 2007, 6:32am UTC](https://www.ruby-forum.com/t/attachment-fu-file-system-storage-change-update/91277/1 "2007-04-06T06:32:23Z")

</div>

Howdy,

It looks like one of the recent updates to attachment\_fu has changed  
the way it names/stores files in the filesystem. I’m guessing it was  
this one:

- add default ID partitioning for attachments

Anyway, my files used to be stored in directories named after the PK.  
Now it seems that things have changed and files are stored with a new  
scheme.

So, anyone have any suggestions as to how I can migrate to the new  
storage setup? All the images in my app are broken.

Thanks,  
Hunter

---

<div class="post-metadata">

**Author:** ![hunter\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bc79bd/32.png) [@hunter\_h](https://www.ruby-forum.com/u/hunter_h)\
**Post date:** [April 8, 2007, 4:45am UTC](https://www.ruby-forum.com/t/attachment-fu-file-system-storage-change-update/91277/2 "2007-04-08T04:45:50Z")

</div>

On 4/5/07, Hunter H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Now it seems that things have changed and files are stored with a new  
> scheme.
> 
> So, anyone have any suggestions as to how I can migrate to the new  
> storage setup? All the images in my app are broken.

Hah, sorry about that. If it makes you feel any better, I broke  
Lighthouse too 🙂

For now, you can just hack your model like so:

```
    def partitioned_path(*args)
      [attachment_path_id] + args
    end

```

I did a manual migration looping through all the records and moving  
them manually. This isn’t the exact code, but something like this  
should work.

class Avatar  
def old\_full\_filename(thumbnail = nil)  
file\_system\_path = (thumbnail ? thumbnail\_class :  
self).attachment\_options[:path\_prefix].to\_s  
File.join(RAILS\_ROOT, file\_system\_path, attachment\_path\_id.to\_s,  
thumbnail\_name\_for(thumbnail))  
end

Avatar.find(:all).each do |av|  
next unless File.exist?(av.old\_full\_filename)  
FileUtils.mkdir\_p(File.dirname(av.full\_filename))  
File.move av.old\_full\_filename, av.full\_filename  
end

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
