0
我期待採取一些陽明:怎樣才能實現自定義種子的Rakefile
My Random Name of a Topic:
Color:
Brown
Blue
Green
Style:
Thin
Fat
而且我想打一個Topic
對象和Item
對象的類型和樣式所有的話結合。
每個那些話都會有type
屬性,如果它的style
或color
主題有一個項目是HABTM會說,所以我也想建立這種連接爲好。
但不要問別人通過一個巨大的答案耕田,我只是在尋找最好的方式來解析這個YAML:
task glass_full_of_yaml: :environment do
File.open(Rails.root + 'lib/words/glass_full_of.yml', 'r') do |file|
YAML::load(file).each do |record|
debugger
# Item.create!(type: record, name: record)
end
end
end
如果我所有的主題被命名爲不同的,我怎麼能選擇其嵌套屬性並創建它們的Item對象?