我有三種模式。客戶,工作和收據。無法刪除Ruby on Rails中的記錄
客戶有很多工作和工作有很多收據。作業屬於客戶,收據屬於作業。
在我的客戶刪除清單中,我想刪除所有的客戶工作和工作收據。這裏是我的控制器代碼
def destroy
customer = Customer.find(params[:id])
customer.jobs.receipts.destroy_all #this line crashes
customer.jobs.destroy_all
customer.destroy
redirect_to customers_url
redirect_to show_todays_jobs_path
end
,說customer.jobs.receipts.destroy_all拋出,指出該收據的方法是未定義的錯誤的行。
但是,在我的作業控制器中,jobs.receipts.destroy_all工作得很好。在客戶控制器中,如果我刪除線來銷燬收據,那麼這也可以正常工作。
我不明白爲什麼我無法刪除客戶控制器中的收據。請幫我在這裏。在此先感謝
能告訴你喬布斯控制器? –
我們需要看到你的模型關係。 –