2011-12-15 39 views
3

這裏該代碼塊拋出的Rails控制檯的警告消息 - 警告:沒有別的搶救也沒用警告:其他沒有救援是沒用的?

def handle_exceptions(e) 
    case e 
    when ActionController::UnknownAction, ActiveRecord::RecordNotFound, ActionController::RoutingError 
     not_found 
    else 
     internal_error(e) 
    end 
    end 

任何線索,爲什麼?

+0

我已經使用Ruby 1.9.3p0在我的rails試圖3.1.3控制檯,似乎是工作的「精」。我的意思是沒有警告......你使用的是什麼紅寶石和鐵軌? – brutuscat 2011-12-17 19:58:19

回答

4

我認爲這個錯誤不是來自你發佈的源代碼,而是來自它被調用的地方。

我可以用這個實現,也使用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