问题
I am using Rails 4.1.14 with rails_admin 0.8.1, mongoid 5.0 and mongoid_paranoia. I created RailsAdmin custom action to restore soft deleted Users.
class Restore
...
register_instance_option :controller do
Proc.new do
object.restore
...
end
end
end
But I keep getting
User with id '5695997df5740c17b0000002' could not be found
From my 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}
The problem is per default_scope query filters out records where deleted_at is not nil. Any suggestions on how to override it?
回答1:
Unfortunately, I'll have to list this as an answer because I do not have the reputation to comment.
I believe your question may be answered here: How do I show unscoped models in Rails Admin?
The way I'd approach it is to create a scope that does satisfy my requirements for RailsAdmin and use that scope instead; that said, in general I try to avoid default_scope
whenever possible.
来源:https://stackoverflow.com/questions/34758736/railsadmin-custom-action-to-restore-soft-deleted-records