Forum: Ruby on Rails Find and order

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2009-04-08 18:51
I have a find that look likes this:

@values = UdidValue.find(:all,
  :conditions => ['udid_id = ?', x.id], :order => 'value ASC')

The problem is that 'value' could be a street address, for example,
numbers. So, when I do the :order if they are strings the get order
wonderfully, but in one case I have values that are numbers, for
example, 234, 233, 219, 25, 199, which get order as 199, 25, 219, 233,
234. Which is not what I want. I would like to order as 25, 199, 219,
233, 234.

Is there a way to get the order to order properly regardless if it is a
number of string? Thanks,

-S
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-08 19:19
(Received via mailing list)
> 233, 234.
>
> Is there a way to get the order to order properly regardless if it
> is a
> number of string? Thanks,

Google for "natural sort" for your particular database.

If mysql, maybe...
http://blog.feedmarker.com/2006/02/01/how-to-do-na...
This topic is locked and can not be replied to.