简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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