Sorting UTF-8 strings in RoR

前端 未结 7 896
暗喜
暗喜 2020-12-09 18:12

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

7条回答
  •  旧巷少年郎
    2020-12-09 18:42

    Have you tried accessing the mb_chars method for each of your country strings? mb_chars is a proxy that ActiveSupport adds that defines Unicode safe versions of all the String methods. If the comparator is Unicode-aware then the sorting should work correctly.

    • mb_chars documentation

提交回复
热议问题