[英]Rails sort list of results
I have list of categories @categories = Category.all
我有类别列表
@categories = Category.all
There are about ten categories. 大约有十个类别。 But I need to change order of them being displayed.
但是我需要更改它们显示的顺序。
I need category with id = n
to be shown first. 我需要先显示
id = n
类别。 This categories already created and filled with items. 此类别已经创建并充满了项目。 So what is the most elegant way to change
@categories
and put category with id=n
first? 那么,更改
@categories
并将id=n
类别@categories
的最优雅方法是什么?
@categories = Category.order("id != #{n}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.