I am unsure what your issue is by looking at the code, I recommend some poor mans debugging - puts
is your friend
Also can you post your model code?
A few rubyish changes you could make to your code
- Array.new is rarely seen in ruby code, use
[]
instead, in this case no need to initialize the variable at all - no need to call
map!
in this case,map
will do - Array (Enumerable) has a method
each_with_index
and you can avoid the x local - use ruby 1.9 hash syntax
example
colors = File.readlines("db/seeds/colornames.csv").map {|name| name.chomp}
hexes = File.readlines("db/seeds/colorhexes.csv").map {|hex| hex.chomp}
Color.delete_all # because I keep having to reseed
colors.each_with_index do |color, index|
Color.create!(name: color, hex: hexes[index])
end
now with some debugging
colors = File.readlines("db/seeds/colornames.csv").map {|name| name.chomp}
hexes = File.readlines("db/seeds/colorhexes.csv").map {|hex| hex.chomp}
puts "Color Count: #{colors.length}"
puts "Hex Count: #{hexes.length}"
Color.delete_all # because I keep having to reseed
colors.each_with_index do |color, index|
puts "#{color}: #{hexes[index}"
Color.create!(name: color, hex: hexes[index])
end
puts "Loaded: #{Color.count} colors"