Skip to content

Instantly share code, notes, and snippets.

@firedev
Last active August 29, 2015 14:04
Show Gist options
  • Save firedev/5d9cd290da97d3c131e3 to your computer and use it in GitHub Desktop.
Save firedev/5d9cd290da97d3c131e3 to your computer and use it in GitHub Desktop.
Seed.rb - imports records from .yml files
# db/seeds.rb
#
# https://gist.github.com/firedev/5d9cd290da97d3c131e3
#
# Imports records from .yml files in db/seed/model.yml
def put_cycle
@r ||= %w(- \\ | /)
print((@r << @r.shift)[0])
print "\b"
end
def seed(class_name)
print "#{class_name}: "
seed_file = File.join(Rails.root, 'db/seed', "#{class_name.to_s.underscore}.yml")
yml = YAML.load_file(seed_file)
yml.each do |item|
item = class_name.create item[1]
if item.valid?
put_cycle
else
puts
puts item.errors.inspect
puts
end
end
print class_name.count
puts
end
seed Model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment