I'm working on a Rails 6 application and in the active-admin
I want to show all the records, including the ones soft-deleted with paranoia
.
I did that adding scope :with_deleted, default: true
.
ActiveAdmin.register Post do
actions :all, except: [:edit, :new]
permit_params :body, :user_id
scope :with_deleted, default: true
end
But when I click on the view
action in the active-admin
dashboard the soft-deleted record I get a
ActiveRecord::RecordNotFound in Admin::PostController#show
Couldn't find Post with 'id'=2 [WHERE "post"."deleted_at" IS NULL]
How can I change the search in the active-admin?
UPDATE: I solve this adding this code to /admin/posts.rb
controller do
def show
@post = Post.find_by_id(params[:id])
end
def scoped_collection
Post.with_deleted
end
end
You can define method
find_resource
oncontroller
scope:Remeber: This method need return one resource, then add
.first
or.last
to your query.In my context I use
findy
and it bring one resource.See the Customizing resource retrieval on https://activeadmin.info/2-resource-customization.html