比方說,我有查詢其取2種按隨機順序帖子:Rails如何分解成數組ActiveRecord AssociationRelation?
@posts = @customer.posts.where("name ? = OR name ? =", "Google", "Yahoo")
這將返回我ActiveRecord_AssociationRelation
對象與給定的職位名稱 我想將它們輸出格式爲:
output = [
# here just google posts,
# here just yahoo posts
]
我該如何選擇數組內的特定帖子?
Google | Yahoo
Test | Test yahoo
Test | Test yahoo
Test | Test yahoo
Test | Test yahoo
Test | Test yahoo
以及如何將結果放入數組中? – user2931706 2015-02-12 08:55:36
以及我如何區分谷歌和雅虎的帖子在最後,因爲它返回給我一個名稱的數組? – user2931706 2015-02-12 09:23:06
你可以在pluck語句中放入你需要的任何字段, – 2015-02-12 10:24:27