Jeremy Woertink wrote:
> but now I have about 10,000 images that are named wrong and not showing.
> I know there is a reprocess! method in paperclip, but it doesn't seem to
> rename the images. Is there already a rake task, or something that will
> do this?
>
> Essentially, I would like to do
>
> MyModel.all.each { |model|
> model.image.set_all_the_styles_to_the_correct_name! }
>
>
> Thanks,
> ~Jeremy
You're right Jeremy, reprocess! won't manipulate the naming or
interpolation. Whatever interpolation you have set *currently* is what
Paperclip will apply, so it won't be able to locate the original files
to reprocess anyhow.
I think your best bet is to work around Paperclip rather than through
it. Take a look at how the previous url would interpolate and compare
that to how the current url will interpolate, then perform directory
creation, moving, and directory removal from there. Because of the
possible url / path permutations I doubt there are any existing rake
tasks that will fit your particular example.
Something similar to:
Model.all.each { |model|
model.file.styles.each do |style|
extension = File.extname(model.image.original_filename)
basename = File.basename(model.image.original_filename, extension)
old_path = File.join(RAILS_ROOT, 'assets', model.class, model.id)
old_file = "#{style}_#{basename}#{extension}"
new_path = File.join(RAILS_ROOT, 'assets', model.class, model.id,
'image')
new_file = "#{style}#{extension}"
FileUtils.mkdir_p new_path unless File.exist?(new_path)
FileUtils.mv File.join(old_path, old_file), File.join(new_path,
new_file)
end
end
Of course that isn't tested, but it should give an idea. This is for the
filesystem and not S3, right?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.