I am trying to figure out a \'proper\' way of sorting UTF-8 strings in Ruby on Rails.
In my application, I have a select box that is populated with countries. As my
The only solution I have found thus far is to use ActiveSupport::Inflector.transliterate(string) to replace the unicode characters with ASCII ones and sort:
Country.all.sort_by do |country|
ActiveSupport::Inflector.transliterate country.name
end
Now the only problem is that this equalizes "ä" with "a" (DIN 5007-1) and I end up with "Ägypten" before "Albanien" while I would expect it to be the other way around. Thankfully the transliteration is configurable about how to replace characters.
See documentation: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate