2

EnquiryForm我和UniversityFeeInstallmentEnquiryForm has_manyUniversityFeeInstallment之间有一对多的关系。
以下是params我从控制器收到的

{
"utf8"=>"✓",
"authenticity_token"=>"jqgiRlk606pDzMEAtS/mGoWz8T61PgyCkKdMzSHEiQA=",
"enquiry"=>{
    "university_fee_installments_attributes"=>{
        "1338318502006"=>{
            "due_date"=>"2012-05-28",
            "amount"=>"1200"
        }
    }
},
"commit"=>"Update Enquiry",
"id"=>"4fc3db492d6d130238000028"

}

我正在使用 Ryan Bates 经典的嵌套形式技术。型号代码也是:

 has_many :development_fee_installments, :autosave => true 
  has_many :university_fee_installments, :autosave => true 
  accepts_nested_attributes_for :development_fee_installments
  accepts_nested_attributes_for :university_fee_installments

控制器:

def update
  @enquiry = Enauiry.find(params[:id])
  if @enquiry.save
    redirect_to enquiry_payments_path(@enquiry, :notice => "Installment details updated")
  else
    render 'edit_installments'
  end
end

我无法保存 university_fee_installments。

4

1 回答 1

1

将您的控制器代码更改为此

def update
    @enquiry = Enquiry.find(params[:id])
    if @enquiry.update_attributes(params[:enquiry])
        redirect_to enquiry_payments_path(@enquiry, :notice => "Installment details updated")
    else
        render 'edit_installments'
    end
end

当我们传递从视图中收到的参数时,update_attributes 将起到作用。

于 2012-05-30T07:04:06.200 回答