而不是創建一個新的父,並創建子項。是否可以從家長列表中進行選擇,然後只創建分配給當前用戶和特定調查的孩子?僅創建子項並選擇嵌套形式的父項?
讓我們用這個例子:
class Survey < ActiveRecord::Base
has_many :questions
accepts_nested_attributes_for :questions
end
class Question < ActiveRecord::Base
belongs_to :survey
belongs_to :user
end
然後在控制器:
def new
# @survey = select menu of all Surveys
3.times do
question = @survey.questions.build
end
end
def create
# Saves new questions with current user
if @survey.save
flash[:notice] = "Success"
redirect_to @survey
else
render :action => 'new'
end
end
我不知道什麼是創造和新的行爲會變成。任何想法?