Forum: Ruby on Rails attachment_fu File System Storage Change - Update?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Hunter H. (Guest)
on 2007-04-06 08:32
(Received via mailing list)
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
Rick O. (Guest)
on 2007-04-08 06:45
(Received via mailing list)
On 4/5/07, Hunter H. <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://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.