比方说,我有查询其取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