Reputation: 6662
I have a one to many relationship between EnquiryForm
and UniversityFeeInstallment
EnquiryForm has_many
UniversityFeeInstallment.
Following is the params
I receive from contoller
{
"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. 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.
Upvotes: 2
Views: 1099
Reputation: 5213
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.
Upvotes: 1