我是 Rails 新手,并且使用Trestle Admin作為我的應用程式的簡單后端解決方案。
當我嘗試洗掉堆疊橋管理后端中的專案時,出現以下錯誤:
PG::ForeignKeyViolation:錯誤:更新或洗掉表“AAA”違反了表“BBB”上的外部 > 鍵約束“fk_rails_xxxxxx” 詳細資訊:鍵 (id)=(2) 仍從表“BBB”中參考。
那很好,但我不想顯示應用程式錯誤,而是想檢查錯誤并顯示自定義警報訊息。我不知道這可能與支架有關。有人知道如何存檔嗎?
謝謝
uj5u.com熱心網友回復:
我發現我可以做這樣的事情,這解決了我的問題:
controller do
def index; end
def destroy
if SecondModal.where(xxx_id: params[:id]).length > 0
flash[:error] = "Record was not destroyed, because it's still referenced in other tables"
redirect_to admin.path(:index)
else
FirstModal.delete(params[:id])
flash[:success] = 'Record destroyed'
redirect_to admin.path(:index)
end
end
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/429664.html
標籤:轨道上的红宝石 ruby-on-rails-7 栈桥管理员
