[英]Activeadmin Destroy Record with Exception Elasticsearch::Transport::Transport::Errors::NotFound in Admin [404]
I've configured Elasticsearch in my Rails application API and for Post model, it's working properly and I'm using @post.destroy!
我已经在Rails应用程序API中配置了Elasticsearch,对于Post模型,它可以正常工作,并且我正在使用@post.destroy!
to delete a specific record without any problem, but when I'm trying the same through Activeadmin panel destroy action (I tried default destroy action and custom controller -> destroy action ), here what's happening is deleting the record properly from db but after deleting it throws an exception : 删除特定记录没有任何问题,但是当我通过Activeadmin面板中的destroy动作(我尝试使用默认的destroy动作和自定义控制器-> destroy action)尝试相同操作时, 这里发生的是从db中正确删除记录,但是删除后它抛出一个异常 :
Elasticsearch::Transport::Transport::Errors::NotFound in Admin::PostsController#destroy
[404] {"found":false,"_index":"posts","_type":"post","_id":"1802","_version":1,"_shards":{"total":2,"successful":1,"failed":0}}
I've tried all custom callbacks which mentioned in elasticsearch-model documentation but the only one solution I found is by using begin .. rescue
statement: 我已经尝试了Elasticsearch-model文档中提到的所有自定义回调,但是我发现的唯一解决方案是使用begin .. rescue
语句:
@deleted = false
begin
@post.destroy!
rescue
Post.find_by(:id => id).present? ? @deleted = false : @deleted = true
#delete successful action here if @deleted == true
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.