Skip to content

Instantly share code, notes, and snippets.

@vinniefranco
Forked from typeoneerror/seeds.rb
Created December 1, 2011 00:53
Show Gist options
  • Save vinniefranco/1412366 to your computer and use it in GitHub Desktop.
Save vinniefranco/1412366 to your computer and use it in GitHub Desktop.
require 'yaml'
asset_path = File.expand_path(File.dirname(__FILE__) + '/../lib/assets/content/')
assets = Dir.glob(asset_path + '/*.yml')
assets.each do |url|
key = File.basename(url, '.yml')
parsed = YAML.load_file(url)
if parsed
klass = Admin.const_get(key.classify)
parsed.each do |data|
item = klass.create(data)
if !item.persisted?
puts "Could not save #{klass.name} because #{item.errors.to_a}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment