diff options
author | David Gay <david@davidgay.org> | 2023-11-02 19:40:23 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2023-11-02 19:40:23 -0400 |
commit | 4869d6fcbd880f448e94aa98912a6ea5bda1dafa (patch) | |
tree | 2673ed5803972b892c3cd8f305ead2ca34544264 /db/seeds.rb | |
parent | bb4eb1113b188ad7f1149df715ae2d9fd0411ca7 (diff) |
Pokemon model, seeded via CSV
Diffstat (limited to 'db/seeds.rb')
-rw-r--r-- | db/seeds.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/db/seeds.rb b/db/seeds.rb index ce6f747..c68e9ae 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,6 +8,8 @@ # MovieGenre.find_or_create_by!(name: genre_name) # end +require "csv" + [ "Pokémon Red", "Pokémon Blue", "Pokémon Yellow", "Pokémon Gold", "Pokémon Silver", "Pokémon Crystal", "Pokémon Ruby", "Pokémon Sapphire", "Pokémon Emerald", @@ -21,3 +23,8 @@ ].each do |title| Game.create(title:) end + +csv_file = Rails.root.join("db/data/pokemon.csv") +CSV.foreach(csv_file, headers: true) do |row| + Pokemon.create(pokedex_num: row["pokedex_num"].to_i, name: row["name"]) +end |