Seeds for different environments

Here’s a little Rails tip for splitting up seed data for various environments: Create the folder db/seeds/. For each environment you want to seed put a file in there named after the env. Your general seeds are put into db/seeds/all.rb. Here’s what it might look like:

| |___all.rb
| |___development.rb
| |___staging.rb
| |___production.rb

Change the content of your db/seeds.rb to something like this:

['all', Rails.env].each do |seed|
  seed_file = "#{Rails.root}/db/seeds/#{seed}.rb"
  if File.exists?(seed_file)
    puts "*** Loading #{seed} seed data"
    require seed_file

Running rake db:seed will now load up the seed data defined in db/seeds/all.rb and the current environment.

iPhone app for GitHub


is GitHub in your pocket: The go to app for staying up to date with your projects on your iPhone, and iPod Touch.
It is