我试图将一个:name,:date对播放到我的rails app中的一个表(通过seed.rd)...不太确定如何做到这一点..我的尝试如下:
[[ "New Years Day", 2013/01/01 ][ "Easter", 2013/03/31]].each do |holiday|
Holiday.create!({:name, :date => holiday})
end
答案 0 :(得分:2)
选项1:
[{ :name => "New Years Day", :date => "2013/01/01" },{ :name => "Easter", :date => "2013/03/31"}].each do |holiday|
Holiday.create!(holiday)
end
选项2:
[[ "New Years Day", "2013/01/01" ],[ "Easter", "2013/03/31"]].each do |holiday|
Holiday.create!({:name => holiday[0], :date => holiday[1]})
end
选项3(实际上并不是一个好的选项,因为当你超越名字和日期时它会变脏):
{ "New Years Day" => "2013/01/01" , "Easter" => "2013/03/31"}.each do |holiday|
Holiday.create!({:name => holiday.first, :date => holiday.second})
end