sorting - Sort alphabetically in rails -
how sort array in rails(alphabetical order). tried
sort_by(&:field_name)
but gives me array capital letter order , lower case order.i tried
array.sort! { |x,y| x.field_name.downcase <=> y.field_name.downcase }
is there way solve this?
you should first downcase every string , sort like:
array = ["john", "alice", "joseph", "anna", "zilhan"] array.sort_by!{ |e| e.downcase } => ["alice", "anna", "john", "joseph", "zilhan"]
Comments
Post a Comment