How do you change how the active admin search for records

Viewed 331

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
0 Answers
Related