我正在使用Rails 4.1.14和rails_admin 0.8.1,mongoid 5.0和mongoid_paranoia。我创建了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
来自我的development.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不为nil的记录。关于如何覆盖它的任何建议?
答案 0 :(得分:1)
不幸的是,我不得不将此列为答案,因为我没有评论的声誉。
我相信你的问题可以在这里得到解答: How do I show unscoped models in Rails Admin?
我接近它的方法是创建一个满足我对RailsAdmin的要求并使用该范围的范围;这就是说,一般来说,我会尽可能避免default_scope
。