On Friday, June 10, 2011 10:13:02 AM UTC-6, Walter Lee Davis wrote: > > > On Jun 10, 2011, at 10:59 AM, Runa wrote: > > > While sorting /ordering text it considers space first, then '.' then > > characters > > > > e.g. @user = User.find(:all,:order=>'name') > > > > it outputs > > > > A Sharma > > A. Bansal ---------------with dot > > Aarti Dev > > > > Is there any way to sort, so that i get the output as > > Aarti Dev > > A. Bansal > > A Sharma > > > > > > http://www.ruby-doc.org/core/classes/Array.html#M000244 > > You want to either use the block form or define your own version of > <=> to use, stripping punctuation and downcasing the input for good > measure to create a "natural" sort. > > Walter > Just beware that if you ever end up using a pagination gem (or rolling your own) such that you get a single "page" of results using limit and offset on your back-end database, this'll screw up any chance of your custom sorting working correctly. If you'll never be using LIMIT and OFFSET SQL clauses, then this works great!
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/E0vUsstTT-oJ. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.