Created
January 28, 2013 06:45
-
-
Save osulyanov/4653521 to your computer and use it in GitHub Desktop.
Move existing Paperclip attachments to a new path Case in:
lib/tasks/copy_paperclip_data.rb
And run:
rake copy_paperclip_data
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 "Copy paperclip data" | |
task :copy_paperclip_data => :environment do | |
@users = User.find :all | |
@users.each do |user| | |
unless user.image_file_name.blank? | |
filename = Rails.root.join('public', 'system', 'images', user.id.to_s, 'original', user.image_file_name) | |
if File.exists? filename | |
image = File.new filename | |
user.image = image | |
user.save | |
image.close | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment