所有しているテーブル側のモデルにhas_one 所属している側のモデルにbelongs_toを設定する。 例:studentsテーブルが、profilesテーブルを所有(profilesテーブルは、studentsテーブルに所属)している場合。 studentsテーブルのカラム id,name profilesテーブルのカラム id,student_id,name 赤字の部分(所有する側のテーブル名の単数形+"_id")をカラムとして定義する。 そして、studentsのモデルは以下のように記述 class Student < ActiveRecord::Base has_one :profile end profiles側はこう class Profile < ActiveRecord::Base belogns_to :student end これで、profiles側のコントローラ等
![[rails]関連(1対1) - noranukoの日記](https://cdn-ak-scissors.b.st-hatena.com/image/square/7bd96f14c0989fb9208519cff4b3c984e36ec269/height=288;version=1;width=512/https%3A%2F%2Fnoranuko.air-nifty.com%2F.shared-cocolog%2Fnifty_managed%2Fimages%2Fweb%2Fogp%2Fdefault.png)