[英]Mongoid- accepts_nested_attributes_for not saving
I have a one to many relationship between EnquiryForm
and UniversityFeeInstallment
EnquiryForm has_many
UniversityFeeInstallment. 我在
EnquiryForm
和UniversityFeeInstallment
之间EnquiryForm
一对多关系。EnquiryForm has_many
UniversityFeeInstallment。
Following is the params
I receive from contoller 以下是我从控制器收到的
params
{
"utf8"=>"✓",
"authenticity_token"=>"jqgiRlk606pDzMEAtS/mGoWz8T61PgyCkKdMzSHEiQA=",
"enquiry"=>{
"university_fee_installments_attributes"=>{
"1338318502006"=>{
"due_date"=>"2012-05-28",
"amount"=>"1200"
}
}
},
"commit"=>"Update Enquiry",
"id"=>"4fc3db492d6d130238000028"
} }
I am using Ryan Bates classic nested form technique. 我正在使用Ryan Bates经典的嵌套表单技术。 Also model code is :
模型代码也是:
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
Controller: 控制器:
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
I am not able to save university_fee_installments. 我无法保存university_fee_installments。
Change your controller code to this 将您的控制器代码更改为此
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 will do the trick as we are passing the params we received from view in that. 当我们传递从视图中接收到的参数时,update_attributes将达到目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.