栈桥管理员自定义删除

Trestle Admin Custom Delete

我是 rails 的新手,使用 Trestle Admin 作为我的应用程序的简单后端解决方案。

当我尝试删除栈桥管理后端中的项目时,出现以下错误:

PG::ForeignKeyViolation: ERROR: update or delete on table "AAA" violates foreign > key constraint "fk_rails_xxxxxx" on table "BBB" DETAIL: Key (id)=(2) is still referenced from table "BBB".

很好,但我不想显示应用程序错误,而是想检查错误并显示自定义警报消息。我不知道这怎么可能与栈桥..有谁知道如何存档这个?

谢谢

我发现我可以做这样的事情,解决了我的问题:

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