LoginSignup
2
3

More than 5 years have passed since last update.

地味に忘れる accepts_nested_attributes_for した時の国際化の定義

Posted at
class ParentModel < ActiveRecord::Base
  has_one  :child, class_name: 'ChildModel'
  accepts_nested_attributes_for :child
end

class ChildModel < ActiveRecord::Base
  has_many :grand_childen, class_name: 'GrandChildModel'
  accepts_nested_attributes_for :grand_childen
end

class GrandChildModel < ActiveRecord::Base
  attr_accessible :name
end

上記の様な model が定義されている場合、 ActiveModel::Translation 内では以下のように国際化処理が行われる。

I18n.translate('activerecord.attributes.parent_model/child/grand_childen.name')

よって、ja.yml ファイルには以下のように定義すれば良い。

ja:
  activerecord:
    attributes:
      parent_model/child/grand_childen:
        name: 孫の名前
2
3
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
3