Skip to content

Commit

Permalink
Leaving image files open is a bad idea when seeding images
Browse files Browse the repository at this point in the history
Fixed no implicit conversion of Hash into String error
  • Loading branch information
Punjab committed Nov 29, 2015
1 parent 1d27459 commit e758a06
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sample/db/samples/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def image(name, type="jpeg")
images_path = Pathname.new(File.dirname(__FILE__)) + "images"
path = images_path + "#{name}.#{type}"
return false if !File.exist?(path)
File.open(path)
path
end

images = {
Expand All @@ -26,7 +26,7 @@ def image(name, type="jpeg")
:attachment => image("ror_tote")
},
{
:attachment => image("ror_tote_back")
:attachment => image("ror_tote_back")
}
],
products[:ror_bag].master => [
Expand Down Expand Up @@ -86,17 +86,23 @@ def image(name, type="jpeg")
products[:ror_baseball_jersey].variants.each do |variant|
color = variant.option_value("tshirt-color").downcase
main_image = image("ror_baseball_jersey_#{color}", "png")
variant.images.create!(:attachment => main_image)
File.open(main_image) do |f|
variant.images.create!(:attachment => f)
end
back_image = image("ror_baseball_jersey_back_#{color}", "png")
if back_image
variant.images.create!(:attachment => back_image)
File.open(back_image) do |f|
variant.images.create!(:attachment => f)
end
end
end

images.each do |variant, attachments|
puts "Loading images for #{variant.product.name}"
attachments.each do |attachment|
variant.images.create!(attachment)
File.open(attachment[:attachment]) do |f|
variant.images.create!(attachment: f)
end
end
end

0 comments on commit e758a06

Please sign in to comment.