Created
December 16, 2011 14:12
-
-
Save dlt/1486178 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
saved = 0 | |
not_saved = 0 | |
Product.all.to_a.select do |p| | |
p.image && p.image.url | |
end.each do |p| | |
begin | |
temp = Tempfile.new("foo") | |
temp.puts \ | |
Mongo::GridFileSystem.new(Mongoid.database). | |
open(p.image.url.sub("/images/", ""), "r"). | |
read. | |
force_encoding("UTF-8") | |
p.image.remove! | |
p.image = temp | |
p.save | |
saved += 1 | |
rescue Exception => e | |
not_saved += 1 | |
pp e.message | |
pp e.class | |
end | |
end | |
puts "salvos: #{saved}\nnao salvos #{not_saved}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment