1
我有一個從Foursquare返回的JSON數組;我們稱之爲@venues
。我希望能夠通過下拉框「選擇」場地,並且我希望它成爲表格的一部分。Rails從JSON數組中選擇
這意味着我希望能夠通過名稱(即在這種情況下,酒店猶他州沙龍)選擇一個特定的場地,並將其保存爲模型id
。爲了澄清,我只會保存我選擇的場地,而不是全部。
通過研究,我發現自己在select
,collection_select
和select_tag
之間感到困惑。請記住,這是直接來自JSON.parse
方法的JSON,不是數據庫模型。
如何在窗體中創建此下拉菜單?
爲了澄清,@venues
看起來是這樣的:
[
{
"beenHere":8,
"venue":{
"id":"3fd66200f964a52023f11ee3",
"name":"Hotel Utah Saloon",
"contact":{
"phone":"4155466300",
"formattedPhone":"(415) 546-6300",
"twitter":"hotelutah"
},
"location":{
"address":"500 4th St",
"crossStreet":"Corner of Bryant",
"lat":37.77947007181946,
"lng":-122.39816943501836,
"postalCode":"94107",
"city":"San Francisco",
"state":"CA",
"country":"United States",
"cc":"US"
},
"categories":[
{
"id":"4bf58dd8d48988d1e9931735",
"name":"Rock Club",
"pluralName":"Rock Clubs",
"shortName":"Rock Club",
"icon":"https:\/\/foursquare.com\/img\/categories\/arts_entertainment\/musicvenue_rockclub.png",
"parents":[
"Arts & Entertainment",
"Music Venues"
],
"primary":true
}
],
"verified":true,
"stats":{
"checkinsCount":6654,
"usersCount":3330,
"tipCount":50
},
"likes":{
"count":0,
"groups":[
]
},
"beenHere":{
"count":0
}
}
}
]
在這種情況下':'是什麼? – Baub
你想要保存場地編號的模型(例如:':venue') – NARKOZ
啊,非常感謝。測試一下,我會回來。 – Baub