5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

enumerizeのI18nではまったこと

Last updated at Posted at 2016-02-04

I18nでyes,noの取り扱いでハマったので備忘録。

class Hoge
  extend Enumerize
  enumerize :fuge, in: [:yes, :no]
end

こんなモデルがあったとして...

localeファイルを追加して

ja:
  enumerize:
    hoge:
      fuge:
        yes: はい!
        no:  いいえ!
hoge = Hoge.new(fuge: Hoge.fuge.yes)
hoge.fuge_text
=> "Yes"

(´・ω`・)エッ?

期待する結果は"はい!"だったのだが・・・

暫く詰まった末に思い出した!!

ja:
  enumerize:
    hoge:
      fuge:
        "yes": はい!
        "no":  いいえ!

keyを囲ってあげないとダメだったんだorz

hoge = Hoge.new(fuge: Hoge.fuge.yes)
hoge.fuge_text
=> "はい!"

これでめでたく使えた(・∀・)

5
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?