我正在使用Rails 3.0。我有一個二維數組。二維數組由用戶數據和布爾值組成。如何從軌道3中的二維數組數組中找到記錄?
例如:[ [user1,true], [user2,true], [user3,false] ]
它看起來是這樣的:
[
[#<User id: 1, email: "[email protected]", username: "abc">, true],
[#<User id: 2, email: "[email protected]", username: "ijk">, true],
[#<User id: 3, email: "[email protected]", username: "xyz">, false],
]
我想找/提取記錄條件;說找到一整行User id=2
,它應該只返回第二行,即[#<User id: 2, email: "[email protected]", username: "ijk">, true]
有反正循環這樣的數組嗎?如何實現?
這是一個簡單的循環;你試過什麼了?順便說一句,你是想僅僅使用內存數組來做到這一點,還是你的目標是高效並只從數據庫加載該記錄? – Zabba
它應該只能有效地抓取一條記錄..我正在檢查以下解決方案... – Bongs