Skip to content

Instantly share code, notes, and snippets.

@ambethia
Created September 15, 2009 16:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ambethia/187440 to your computer and use it in GitHub Desktop.
Save ambethia/187440 to your computer and use it in GitHub Desktop.
Using environment specific yaml fixtures as seed data in Rails 2.3.4
# == Using environment specific yaml fixtures as seed data in Rails 2.3.4
#
# Setup your directory structure like below:
#
# -- RAILS_ROOT
# `-- db
# |-- seeds
# | |-- development
# | | |-- books.yml
# | | `-- users.yml
# | `-- production
# | `-- users.yml
# `-- seeds.rb
#
# And put this block in your `seeds.rb` file:
#
Dir[Rails.root.join('db', 'seeds', Rails.env, '*.yml')].each do |seed|
documents = YAML.load_file(seed)
klass = File.basename(seed, '.yml').classify.constantize
documents.each do |doc|
klass.create(doc.last)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment