警告:其他没有救援是没用的?
问题描述:
这里该代码块抛出的Rails控制台的警告消息 - 警告:没有别的抢救也没用警告:其他没有救援是没用的?
def handle_exceptions(e)
case e
when ActionController::UnknownAction, ActiveRecord::RecordNotFound, ActionController::RoutingError
not_found
else
internal_error(e)
end
end
任何线索,为什么?
答
我认为这个错误不是来自你发布的源代码,而是来自它被调用的地方。
我可以用这个实现,也使用1.9.2-P290证明这一点:
module ActionController
class UnknownAction; end
class RoutingError; end
end
module ActiveRecord
class RecordNotFound; end
end
class Test
def test_exception
raise "error"
rescue
handle_exceptions($!)
end
def test_failing
else puts "invalid"
end
end
def not_found
puts "not found"
end
def internal_error(e)
puts e
end
def handle_exceptions(e)
case e
when ActionController::UnknownAction, ActiveRecord::RecordNotFound, ActionController::RoutingError
not_found
else
internal_error(e)
end
end
end
Test.new.test_exception
Test.new.test_failing
我已经使用Ruby 1.9.3p0在我的rails试图3.1.3控制台,似乎是工作的“精”。我的意思是没有警告......你使用的是什么红宝石和铁轨? – brutuscat 2011-12-17 19:58:19