· 1 min read
Screencast: Seed Data
Ryan Bates zeigt in seinem Screencast wie man dies lösen kann.
Downloadlinks: Download (13.5 MB, 7:56) Alternativer download für iPod & Apple TV (9.3 MB, 7:56)
Weitere Ressourcen:
Quellcode:
[bash] script/generate model operating_system name:string script/generate model country name:string code:string rake db:migrate rake db:seed [/bash]
[ruby] # db/seeds.rb require ‘open-uri’ require ‘active_record/fixtures’
[“Windows”, “Linux”, “Mac OS X”].each do |os| OperatingSystem.find_or_create_by_name(os) end
Country.delete_all open(“http://openconcept.ca/sites/openconcept.ca/files/country\_code\_drupal\_0.txt”) do |countries| countries.read.each_line do |country| code, name = country.chomp.split(”|”) Country.create!(:name => name, :code => code) end end
Fixtures.create_fixtures(”#{Rails.root}/test/fixtures”, “operating_systems”) [/ruby]