I want to sort by two columns, one is a DateTime (updated_at
), and the other is a Decimal (Price)
I would like to be able to sort first by updated_at, t
None of these worked for me! After exactly 2 days of looking top and bottom over the internet, I found a solution!!
lets say you have many columns in the products table including: special_price and msrp. These are the two columns we are trying to sort with.
Okay, First in your Model add this line:
named_scope :sorted_by_special_price_asc_msrp_asc, { :order => 'special_price asc,msrp asc' }
Second, in the Product Controller, add where you need to perform the search:
@search = Product.sorted_by_special_price_asc_msrp_asc.search(search_params)