2011-10-23 11 views
0

以下のようにnested_attributes_forを使用する方法はありますか? 基本的には、1人または複数の車を作成し、各車に詳細を追加したいと考えています。これはまさに現実的な例ではなく、モックアップです。まだ作成されていないので、車の詳細を構築しようとすると、私はうんざりする。accepts_nested_attributes_for - belongs_to、has_many、fields_for

モデル:

class Person < ActiveRecord::Base 
    has_many :cars 
    accepts_nested_attributes_for :car 
end 

class Car < ActiveRecord::Base 
    belongs_to :person 
    has_many :details 
    accepts_nested_attributes_for :details 
end 

class Detail < ActiveRecord::Base 
    belongs_to :car 
end 

フォーム:

form_for @person do |f| 
    #fields 
    f.fields_for :car do |car| 
    #fields 
    car.fields_for :details |detail| 
     =detail.text_field :content 
    end 
    end 
end 

答えて

関連する問題