如何在Activeadmin中为我的所有资源挽救ActiveRecord :: RecordNotFound?
我知道在Rails中我可以将rescue_from(ActiveRecord::RecordNotFound)
放在ApplicationController中,在ActiveAdmin中有相同的方法吗?
答案 0 :(得分:6)
ActiveAdmin.register FooBar do
controller do
rescue_from ActiveRecord::RecordNotFound, with: :show_errors
def show_errors
# ...
end
end
end
编辑: 您可以在一个地方为所有资源执行此操作:
require 'active_admin/base_controller'
ActiveAdmin::BaseController.class_eval do
rescue_from ActiveRecord::RecordNotFound, with: :show_errors
def show_errors
# ...
end
end