我在我的rails3.2应用程序中有一个表单,用于投诉,它也同时构建一个新的公司和分支。这一切都可以正常工作,但我想将公司的ID作为外键company_id存储在分支表中。与导轨嵌套的表格
这是我投诉的控制器:
def new
@complaint = Complaint.new
@complaint.build_company
@complaint.build_branch(:company_id => '#Trying to set the company ID here')
respond_to do |format|
format.html # new.html.erb
format.json { render json: @complaint }
end
end
我可以把:company_id =>
后分配上面创建的对象的ID?
我需要某种形式的'after_create'行动做到这一点? – pjmil 2013-03-20 08:02:10
你看过使用accept_nested_attributes_for和嵌套窗体吗? – 2013-03-21 03:40:03