1
我現在坐在這裏8小時,以弄清楚它是如何工作的:我試圖將http://asciicasts.com/episodes/196-nested-model-form-part-1中的示例修改爲一對一的關係。嵌套的屬性與一對一的關係
class Survey < ActiveRecord::Base
has_one :question, :dependent => :destroy
accepts_nested_attributes_for :question
end
class Question < ActiveRecord::Base
belongs_to :survey
end
控制器:
def new
@survey = Survey.new
@survey.questions.build
end
如果我使用像一個一對多的關係,它的偉大工程:
class Survey < ActiveRecord::Base
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions
end
我在做什麼錯?
什麼是失敗和在哪裏?你可以發佈你的視圖代碼或一些錯誤? –