What is the best way to seed a database in Rails?

Updating since these answers are slightly outdated (although some still apply). Simple feature added in rails 2.3.4, db/seeds.rb Provides a new rake task rake db:seed Good for populating common static records like states, countries, etc… http://railscasts.com/episodes/179-seed-data *Note that you can use fixtures if you had already created them to also populate with the db:seed task … Read more

How to load db:seed data into test database automatically?

The db:seed rake task primarily just loads the db/seeds.rb script. Therefore just execute that file to load the data. load “#{Rails.root}/db/seeds.rb” # or Rails.application.load_seed Where to place that depends on what testing framework you are using and whether you want it to be loaded before every test or just once at the beginning. You could … Read more

Java random numbers using a seed

If you’re giving the same seed, that’s normal. That’s an important feature allowing tests. Check this to understand pseudo random generation and seeds: Pseudorandom number generator A pseudorandom number generator (PRNG), also known as a deterministic random bit generator DRBG, is an algorithm for generating a sequence of numbers that approximates the properties of random … Read more