0
我正在使用嵌套窗體來實現Rails 4應用程序。我有嵌套字段的形式。創建工作正常:將變量傳遞給Rails控制器方法中的渲染
def create_medical_history
@patient_id = params[:patient]
@medical_history = MedicalHistory.new(medical_history_params)
if @medical_history.save
redirect_to patient_path(@patient_id)
else
render 'new_medical_history'
end
end
問題是在其他條件。首先在我的表單中我定義了@patient
變量,所以當我的render new_medical_history
@patient變量變爲零時。
我需要再次通過它。我怎樣才能做到這一點?
你可以在渲染髮生之前製作一個全局變量來保存該值嗎? – Rana
您想在新的請求中再次獲得'@ patient':即'@patient = Patient.find(@patient_id)'?確保查看此用戶的用戶可以看到此內容(即使用CanCan或Pundit)。 – Carpetsmoker