我要做的是在通过控制器创建项目后更新它的属性,如下所示:
def create
@check_out = CheckOut.new(params[:check_out])
@check_out.request_id = @request.id
@check_out.status = 'complete'
@check_out.date_taken = Time.now
etc.....
respond_to do |format|
if @check_out.save
format.html { redirect_to(@check_out, :notice => 'Check out was successfully created.') }
format.xml { render :xml => @check_out, :status => :created, :location => @check_out }
else
format.html { render :action => "new" }
format.xml { render :xml => @check_out.errors, :status => :unprocessable_entity }
end
end
end
问题是创建的项目是通过嵌套属性创建的。通过痛苦的反复试验,我开始意识到,创建嵌套项目时,不是通过它们的控制器,而是通过其他方式。我需要弄清楚这是如何完成的,所以我可以尝试提出解决方案。