Rails seeds
A seeds file is a great addition to a new Rails project. Seed data will allow you to populate your developing app quickly, and unlike manually entering sample data, a seeds file can be run over and over as you work.
When working on an existing code base, creating seed data is a safe way to learn the data model. And faker
can be added to generate data for performance testing.
faker initial seeds replant
# db/seeds.rb
require "faker"
return if Rails.env.production? # in case someone runs db:seed instead of db:seed:replant
10.times do
User.create!(
Faker::Name::name,
password: "Not2secret",
Faker::Internet.email
)
end
# Initial creating and seeding of database
$ rails db:seed
# or
$ rails db:seed:replant