How to perform natural sorting on model and result should be in ActiveRecord::Relation ?

34 views
Skip to first unread message

Fahim Patel

unread,
Feb 21, 2015, 1:23:30 AM2/21/15
to rubyonra...@googlegroups.com
Hello All,

I need to perform natural sorting on alphanumeric column's data and even return  type should be ActiveRecord::Relation. I tried 'naturally' and ''naturalsorter'' gem but not successful.Below link explain what is natural sorting. 


Thanks! in advance


Fahim Patel

unread,
Feb 21, 2015, 5:08:29 AM2/21/15
to rubyonra...@googlegroups.com
Found the solution. Change the 'col_name' with your table alphanumeric column name. 

MyModel.order("LENGTH(col_name)").order(:col_name)
Reply all
Reply to author
Forward
0 new messages