A file in the app / db directory used to create records.
You don't have to manually register the data one by one when creating a record. Seeds.rb allows you to create a large number of records with a single command.
Describe as follows in app / db / seeds.rb,
seeds.rb
100.times do |n|
User.create(name: "name#{n}", email: "mail#{n}@gmail.com")
end
When you run ** rails db: seed **, The users table has name and email values respectively
"name0, [email protected]", "name1, [email protected]", ・ ・ ・ "name99, [email protected]"
100 records are registered as shown in.
Recommended Posts