0
我有一個關於使用update_attributes分配值的noob問題。如何爲rails中的update_attributes賦值?
在考試控制器中,保存新的考試記錄,然後檢索與某些新考試字段匹配的患者記錄。這部分工作正常。
@exam.save
@patient = Patient.joins(:charts).where(:dob => @exam.patient_dob).where(:charts => { :provider_id => @exam.provider_id, :patient_mrn => @exam.patient_mrn })
然後我嘗試使用它的崩潰和燒傷以下更新從@patient記錄中的值新記錄@exam ......
@exam.update_attributes(:patient_id, @patient.id)
怎麼會有我走了這麼誤入歧途?
東西這裏要注意** ** update_attribute不及格的驗證規則,但你的update_attributes是 – 2013-04-23 04:20:15
我選擇了驗證規則update_attributes方法。但無論如何,我認爲我的散列格式不正確的任何一個。 我得到未定義的方法'id'爲# -any建議? –
user2284821
2013-04-23 05:38:50
絕對 - 「哪裏」將永遠返回你的關係,即。對象列表。如果你只想要第一個,就調用'.first'。 – sevenseacat 2013-04-23 06:19:36