LoginSignup
2
1

More than 1 year has passed since last update.

Rails: ActiveModel の table_for を i18nに対応させる

Last updated at Posted at 2015-09-10

table_for に直接 i18n を指定して、モデルオブジェクトを渡す。

/app/admin/human.rb
table_for humans, i18n: Human do
  column :name
  column :gender { |result| result.gender }
end

モデルでは ActiveModel を include するだけで良い。

/app/models/human.rb
class Human
  include ActiveModel::Model
end

locales ファイルを設定する。(記述場所は activerecord: の下ではないので注意)

/config/locales/ja.yml
ja:
  activemodel:
    attributes:
      human:
        name: 名前
        gender: 性別

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

2
1
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
2
1