我試圖通過傳遞該記錄的id來刪除記錄。代碼如下所示:在刪除Rails中的記錄時找不到記錄錯誤
def destroy_catalogue_entry
@catalogue_entry = CatalogueEntry.find(params[:catalogue_entry_id])
if @catalogue_entry.destroy
flash[:success] = 'Catalogue entry deleted successfully.'
else
flash[:error] = 'Failed...'
end
end
我收到了一個有趣的錯誤。當我的函數destroy_catalogue_entry
把它叫做表明:
Couldn't find CatalogueEntry with 'id'=16
但我如果條件部發表評論,並呈現@catalogue_entry
爲JSON,輸出打印成功。那麼怎麼可能?我犯了一些愚蠢的錯誤還是有邏輯的原因。請賜教。
什麼是在此操作時在控制檯中生成的sql查詢? – Richlewis
你可以在控制檯中執行這些操作,並在此輸出: –