用于恢复软删除记录的 RailsAdmin 自定义操作

RailsAdmin custom action to restore soft deleted records

我正在使用 Rails 4.1.14 和 rails_admin 0.8.1、mongoid 5.0 和 mongoid_paranoia. I created RailsAdmin custom action 来恢复软删除的用户。

class Restore
  ...
  register_instance_option :controller do
    Proc.new do
      object.restore
      ...
    end
  end
end

但我不断得到

User with id '5695997df5740c17b0000002' could not be found

来自我的develoment.log

Started GET "/admin/user/5695997df5740c17b0000002/restore" for 127.0.0.1 at 2016-01-12 16:35:04 -0800
Processing by RailsAdmin::MainController#restore as HTML
  Parameters: {"model_name"=>"user", "id"=>"5695997df5740c17b0000002"}
MONGODB | localhost:27017 | rails425_dev.find | STARTED | {"find"=>"users", "filter"=>{"deleted_at"=>nil, "_id"=>BSON::ObjectId('56956c76f5740c1d68000000')}, "limit"=>-1}

问题是每个 default_scope 查询过滤掉 deleted_at 不为零的记录。关于如何覆盖它的任何建议?

不幸的是,我不得不将此列为答案,因为我没有发表评论的名誉。

我相信您的问题可以在这里得到解答: How do I show unscoped models in Rails Admin?

我的方法是创建一个确实满足我对 RailsAdmin 的要求的范围,然后改用该范围;也就是说,一般来说,我会尽可能避免 default_scope