1

Let's say I have a collection products with the following values for "name":

  • Awesome sneakers
  • Boring Umbrella
  • 420 product

The following code:

@products.reorder('name ASC') # I really need to use reorder in my code

will list the results as-is:

  • 420 product
  • Awesome sneakers
  • Boring Umbrella

What should I tweak in reorder() to have the following order:

  • Awesome sneakers
  • Boring Umbrella
  • 420 product
Jeremie Ges
  • 2,747
  • 3
  • 22
  • 37

2 Answers2

1
@products.reorder("(name ~ '^[0-9]'), name")

Explanation: FALSE sorts before TRUE so digit values will be last.

Alex Baidan
  • 1,065
  • 7
  • 15
0
@products.reorder("(name !~* '^[a-z]'), name")
codenamev
  • 2,203
  • 18
  • 24