简体   繁体   English

从Rails查询中排序帖子

[英]sorting posts from query in rails

I have made a query on posts (which is included in a has_many belongs_to assoc. with users). 我已经对posts进行了查询(与用户一起包含在has_many当属组织中)。 So, with this query, I have a selection of posts in @selected_posts is there any way I can categorize and sort the users that have posts included in this query and sort them by name with a count of posts? 因此,通过此查询,我可以在@selected_posts选择posts ,有什么方法可以对包含在该查询中的帖子的用户进行分类和排序,并通过带有帖子数的名称对其进行排序? ( Like Mike (6) as link to Mike's 6 posts) for example? (例如,像Mike(6)一样链接到Mike的6个帖子)?

You can use group_by. 您可以使用group_by。 There is excellent documentation on this in the api docs here http://apidock.com/rails/Enumerable/group_by 此处的api文档中有关于此方面的出色文档,网址为http://apidock.com/rails/Enumerable/group_by

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM