-1

I currently have the following files in my app:

image1.jpg
image2.jpg
image3.jpg
...
image10.jpg
...
image20.jpg

However, when I try to query them in Rails (hopefully achieving the same order as above), I get the following order:

image10.jpg
image11.jpg
...
image19.jpg
image1.jpg
image20.jpg

Here is the method I am using:

Image.order("picture_file_name ASC")

Is it possible to display them in the same order as the first option?

Thanks!

Dodinas
  • 6,705
  • 22
  • 76
  • 108
  • The easiest way to achieve this is to include the leading zeroes immediately in the filename, so instead of creating image1.jpg, immediately create image00001.jpg, etc., if at least naming the files in under your control... – Danny Jan 28 '14 at 21:23
  • Thanks @Danny, I figured that. Unfortunately, I am dealing with thousands of pre-named files. So it is, as you say, out of my control. – Dodinas Jan 28 '14 at 21:25

1 Answers1

0

The accepted answer from this question will probably be of some help here:

MySQL 'Order By' - sorting alphanumeric correctly

Community
  • 1
  • 1
Jon
  • 10,678
  • 2
  • 36
  • 48