2012-04-13 103 views
0

我正在创建一个使用sinatra + mongoid的应用程序。我有两个models,联系人有很多电话。为了测试我的末日控制器我后我的数据与此命令`sinatra + mongoid

curl -X POST -d "contact[name]=nome&contact[email][email protected]&contact[phone][0][number]=88888888&contact[phone][0][type]=1&contact[phone][2][number]=77777777&contact[phone][3][type]=1" 

但是当我在MongoDB中做一个查询我看到不保存预期。我需要那个电话班会用数组保存,但现在电话是一个散列,其中键是“0”,“1”,N像我的发布数据。我该如何解决这个问题?我想数据被保存如此:

{ 
"_id":"4f889875b336e722a0000003", 
"email":"[email protected]", 
"github":"diegodfsd", 
"name":"diego2", 
"phone":{ 
"0":{ 
"number":"89311768", 
"type":"cellphone" 
}, 
"1":{ 
"number":"55555555", 
"type":"home" 
} 
}, 
"twitter":"diegodfsd" 
} 

gist

回答

1

你需要使用的,而不是手机

curl -X POST -d "contact[name]=nome&contact[email][email protected]&contact[phones_attributes][0][number]=88888888&contact[phones_attributes][0][type]=1&contact[phones_attributes][2][number]=77777777&contact[phones_attributes][3][type]=1" 
+0

这没有改变什么phones_attributes PARAMS。我希望将数据保存为数组而不是散列。我需要保存:https://gist.github.com/2399768 – 2012-04-16 16:24:12