0
0

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.

I18nでno: hogeって書いたらキーがfalseになったでござる

Posted at

ActiveRecordのカラム名をI18n使って多言語化する場合

ここにありますが、キーにyesとかno使うと意図した動作をしません
[https://makandracards.com/makandra/24809-yaml-keys-like-yes-or-no-evaluate-to-true-and-false]

  question:
    contents: 質問内容
    no: 表示順

こう書いていたのですが、どうにもビューに「表示順」と出てくれないで「No」と出ます
コンソールで調べてみたら

I18n.t('activerecord.attributes.question')
=> {:contents=>"質問内容", false=>"表示順"}

あれ?? :noというキーがない。。。falseってなんだよ

以下のように修正することで解決しました! I18nというよりRubyでYAML使う時の注意ですね

  question:
    contents: 質問内容
    'no': 表示順
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?