Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@ryosuke_sato

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

More than 5 years have passed since last update.
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: 孫の名前
3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
feedforce
『「働く」を豊かにする。』というミッションを掲げ、企業向けネットサービスを開発・提供しています。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?