@Sasha の助けを借りて、患者の治療用にネストされたフォームを作成しました。
今、私はこのエラーを受け取ります:
UnknownAttributeError in PatientsController#update
unknown attribute: treatment
私の患者の更新コントローラーは、実際には次のようになります。
def update
@patient = Patient.find(params[:id])
respond_to do |format|
if @patient.update_attributes(params[:patient])
format.html { redirect_to @patient, notice: 'Patient was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @patient.errors, status: :unprocessable_entity }
end
end
end
そして、次のようなフォーム:
<%= form_for @patient do |f| %>
<%= f.fields_for ([@patient, @patient.treatments.build]) do |tf| %>
<%= render 'treatment_form', form: tf %>
<% end %>
<%= f.fields_for ([@patient, @patient.treatments.build]) do |tf| %>
<%= render 'treatment_form', form: tf %>
<% end %>
<%= f.submit %>
<% end %>
だから私は患者のコントローラーに何を追加しなければならないのか分かりませんか?
@JimLim が推奨するようにコードを変更しましたが、同じエラーが発生します。
ActiveRecord::UnknownAttributeError in PatientsController#update
unknown attribute: treatment
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"OPuS9Mmk3guiV20nkw5OaPUFyjVow49H+MMxY37O0r0=",
"patient"=>{"treatment"=>{"category_id"=>"9",
"content"=>"dsfsdf",
"day"=>"2013-07-21"}},
"commit"=>"Update Patient",
"id"=>"9"}