Order_by several fields, including logical

I am trying to arrange my default_scope so that the hieroglyphs with boolean important = true displayed first, and the whole order from created_at desc.

So, I have the following code:

 default_scope order_by(:important => :desc, :created_at => :desc) 

But it seems that the order of the important fields is ignored.

How can I make it work?

Thank you in advance


EDIT:

I just shift the order of the order parameters and it works:

 default_scope order_by(:created_at => :desc, :important => :desc) 

Just so simple.

+4
source share
1 answer

This is an example of how to sort two columns in rails (you might have to change it a bit to suit your requirement), but I think you get the idea

 <Model>.all(:order => 'important, created_at') 

NTN

+2
source

Source: https://habr.com/ru/post/1443673/


All Articles