Created
September 19, 2009 13:03
-
-
Save dmitry/189479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Moves files to a new :path NB! backup your files before use this task (set CLASS and PATH, ATTACHMENT is optional)" | |
task :change_path => :environment do | |
raise 'PATH must be specified, like PATH=:rails_root/public/system/:class/:attachment/:style/:id.:extension' if ENV['PATH'].blank? | |
path = ENV['PATH'] | |
for_all_attachments do |instance, name| | |
object = instance.send(name) | |
old_path = object.instance_variable_get :'@path' | |
styles = [:original] + object.styles.keys | |
styles.each do |style| | |
if object.exists?(style) | |
object.queued_for_write[style] = object.to_file(style) | |
end | |
end | |
object.instance_variable_set :'@path', path | |
object.flush_writes | |
object.instance_variable_set :'@path', old_path | |
object.instance_variable_set :'@queued_for_delete', styles.map { |style| object.path(style) } | |
object.flush_deletes | |
# if stopped working then use: | |
# path = Paperclip::Interpolations.interpolate(path, object, style) | |
# and own write and delete functions | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment