How do you overlay multiple default models on a model?

I was wondering how you have several default areas (ordering) on ​​the model, for example, I have a comment model that requires ordering by date and statement:

default_scope :order => 'approved ASC', :order => 'date ASC'

So, how do you have both of these orders per model, so I order first approved, and then by date.

Hooray!

+3
source share
2 answers

Here is a good syntax for ordering with multiple fields:

default_scope :order => 'approved ASC, date ASC'
+6
source

In Rails 4+, you can:

default_scope -> { order(approved: :asc, date: :asc) }
+7
source

All Articles