下面是一些 sudo 代码:
异常.rb
module Exceptions
class CriticalError < StandardError
# Question: How do I attach a callback to this error? Whenever this error is raised, I also want it to ping_me() as a after callback
def ping_me()
...
end
end
end
期望的结果:
raise Exceptions::CriticalError # after a callback to this error being raised, it will run the ping_me() method
问题:
我如何在rails中做到这一点?我看到了一种rescue_from
方法,但我认为它只能在控制器内部使用
非常感谢!