💎 Ruby on Rails
Beginner
What is database seeding in Rails?
Answer
Database seeding populates the database with initial or sample data using the db/seeds.rb file. Run with rails db:seed. Seeds are useful for: creating an admin user, populating lookup tables, and generating demo data for development. Example: User.create!(name: 'Admin', email: 'admin@example.com', password: 'password'). The find_or_create_by method is useful in seeds to avoid duplicates when re-running. For large datasets or organized seeds, use the Seedbank gem or separate seeder files.