简体   繁体   English

红宝石在轨道上-按两列排序结果

[英]ruby on rails- Order results by two columns

i've got an article table (model Article) that i want to order by two boolean columns (:foreground, :on_evidence) for show some results in a view 我有一个文章表(模型文章),我想按两个布尔列(:foreground,:on_evidence)进行排序,以便在视图中显示一些结果

in the controller of the view in the action index: 在操作索引的视图控制器中:

class ShowController < ApplicationController
  def index
    @articles = Article.where("published = true ").order('foreground, on_evidence')
  end
end

this method is wrong...how can i do for this trouble? 这种方法是错误的...我该怎么办?

Ok i've found the solution simply i've changed the find query: 好的,我已经找到了解决方案,只是我更改了查找查询:

class ShowController < ApplicationController
  def index
    @articles = Article.where('published = true').order(foreground: :desc)
  end
end

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

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