1
我是ruby-newbie,我需要從YAML播種我的數據庫。在seeds.rb加載YAML後我得到這個數組的哈希:從YAML播種數據庫
{"projects"=>[{"title"=>"Family", "todos"=>[{"text"=>"buy a milk", "isCompleted"=>false},
{"text"=>"Change oil in engine", "isCompleted"=>false},
{"text"=>"To send the letter", "isCompleted"=>true},
{"text"=>"To drink smt", "isCompleted"=>false}, {"text"=>"Buy t-shirt", "isCompleted"=>false}]},
{"title"=>"Job", "todos"=>[{"text"=>"Call chief", "isCompleted"=>true},
{"text"=>"To send documents", "isCompleted"=>true},
{"text"=>"Make todolist", "isCompleted"=>false}]},
{"title"=>"Other", "todos"=>[{"text"=>"To call friend", "isCompleted"=>false},
{"text"=>"Prepare for trip", "isCompleted"=>false}]}]}
我的代碼:
seed_file = Rails.root.join('db', 'seeds', 'seeds.yml')
config = HashWithIndifferentAccess.new(YAML::load_file(seed_file))
如何我可以遍歷並創建新的項目和託多斯?請幫忙!
太謝謝你了! – GreenSpike