隨着@Sasha的幫助下,我在患者創造了一個嵌套形式處理:UnknownAttributeError在控制器
現在我得到這個錯誤:
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 recomended,但我得到了同樣的錯誤:
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"}
您的患者模型是什麼樣的? – pdoherty926
attr_accessible:改變,:nachnahme,:ORT,:大街,:電話,:vorname,:treatment_attributes,:治療 的has_many:治療 的has_many:類別,:通過=>:治療 的has_many:畫,:通過=>:治療 accep_nested_attributes_for:治療 –
再次。 「治療」不應該attr_accessible。這不是病人的特徵;這完全是另一種模式。您有治療屬性(可能需要更改爲treatments_attributes,不確定),因爲您說您接受*屬性*進行治療,但治療本身不是患者模型的一部分。如果你刪除它,它可能會修復一些問題。無論如何,它可能應該被刪除。 – Sasha