Skip to content

Instantly share code, notes, and snippets.

@dlt
Created December 16, 2011 14:12
Show Gist options
  • Save dlt/1486178 to your computer and use it in GitHub Desktop.
Save dlt/1486178 to your computer and use it in GitHub Desktop.
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