Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rescue RecordNotFound in Activeadmin

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?

like image 636
kirlev Avatar asked Oct 28 '25 09:10

kirlev


1 Answers

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
like image 192
Timo Schilling Avatar answered Oct 31 '25 02:10

Timo Schilling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!