我在我的Rails应用程序API中配置了Elasticsearch,对于Post模型,它正常工作,我使用@post.destroy!删除一个特定的记录,没有任何问题,但是当我尝试通过Activeadmin面板销毁操作(我尝试了默认销毁操作和自定义控制器->破坏操作)时,这里发生的事情是正确地从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}}发布于 2016-10-06 06:54:06
我尝试了弹性搜索-模型文档中提到的所有自定义回调,但我找到的唯一解决方案是使用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
endhttps://stackoverflow.com/questions/39746337
复制相似问题