2011-02-07 31 views
0

在我的ApplicationController中,我有为什么rails 2.1不能用rescue_from捕获异常?

rescue_from StorageExceptions::AuthorizationFailed, :with => handle_auth_error 

def handle_auth_error 
    redirect_to error_path(403) 
end 

但代码没有赶上这个错误。我已经检查了被捕获的是NameError的消息:“未被捕获的抛出`StorageExceptions :: AuthorizationFailed'”

为什么是这个以及如何捕获实际的错误?

+0

似乎由于某种原因,错误被转换为堆栈中某处的NameError。我想不出为什么,'因为我无法找到它出现在名称错误的地方。 – cmouse 2011-02-07 20:34:37

+0

和hades的名字是'perform_action_without_rescue'?我找不到任何地方 – cmouse 2011-02-07 20:50:26

回答

0

我有麻烦了rescue_from ..., :with => ...语法在我的Rails工作(2.3.8)的应用程序,太 - 我解决它通过使用可替代rescue_from ... do ... end形式:

rescue_from(ActionController::InvalidAuthenticityToken) do |e| 
    #TODO: Flash something? 
    logger.error "! Invalid authenticity token when accessing #{request.url}" 
    render(:template => 'sessions/new', :layout => 'pre_login') 
end 

我从来没有想通了,为什么第一种形式永远工作,虽然...

希望这有助于!

相关问题