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.
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 Hunter Hillegas (Guest)
on 2007-04-06 06: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
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-04-08 04:45
(Received via mailing list)
On 4/5/07, Hunter Hillegas <lists@lastonepicked.com> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.