Search code examples
ruby-on-railsrubysimple-formrails-i18n

i18n with Enumerize gem


I am using Enumerize gem https://github.com/brainspec/enumerize/ It allows me use beautiful selects in form with siple form. And all options in this selects are translated.

en:
  enumerize:
    user:
      sex:
        male: 'Man'
        female: 'Woman'

So, in my form I have select with variants 'Man' and 'Woman'. When I save the record with 'Man' value I get sex attribute with 'male' value. Now I want to display this value as 'Man' on the show page, but

= @user.sex

outputs as 'male' instead of 'Man'


Solution

  • I'd probably use the .text method (you can see it inside the Gem by using bundle open enumerize and traversing the code a bit)

    = @user.sex.text
    

    You can also use the full translation key

    = t("activerecord.enumerize.user.sex.#{@user.sex}")