Search code examples
rubyruby-on-rails-3globalize2

Sorting model instances with Globalize3


The problem seems trivial, but I can't find any reasonable solution. I have list of countries with translations stored in Globalize3 translation tables. How can I fetch the list of countries sorted by name?

Country name isn't stored directly in the model, but in separate table. Is there any reasonable way to sort the result other than manual sql query, or manualy sorting result table after AR query is complete?


Solution

  • Country.with_translations(I18n.locale).order('name') for current locale.

    Edit:

    You can also use fallbacks:

    Country.with_translations(I18n.fallbacks[I18n.locale]).order('name')