Rescuable
class ApplicationController < ActionController::Base
# 一个或多个异常类,有 :with 选项
rescue_from User::NotAuthorized, with: :deny_access # 自定义的异常处理方法
rescue_from ActiveRecord::RecordInvalid, with: :show_errors
# 一个或多个异常类,传递 block
rescue_from 'MyAppError::Base' do |exception|
render xml: exception, status: 500
end
protected
def deny_access
# ...
end
def show_errors(exception)
exception.record.new_record? ? ...
end
end最后更新于