rescue RecordNotFound in Activeadmin

1.9k views Asked by At

How can I rescue ActiveRecord::RecordNotFound in Activeadmin for all my resources?

I know in Rails I can put rescue_from(ActiveRecord::RecordNotFound) in the ApplicationController, is there an equivalent way of doing this in ActiveAdmin?

1

There are 1 answers

2
Timo Schilling On BEST ANSWER
ActiveAdmin.register FooBar do
  controller do
    rescue_from ActiveRecord::RecordNotFound, with: :show_errors
    def show_errors
      # ...
    end
  end
end

EDIT: You can do this at one place for all resources:

require 'active_admin/base_controller'
ActiveAdmin::BaseController.class_eval do
  rescue_from ActiveRecord::RecordNotFound, with: :show_errors
  def show_errors
    # ...
  end
end