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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -