ruby on rails 3.1全局异常处理程序 [英] ruby on rails 3.1 global exception handler
本文介绍了ruby on rails 3.1全局异常处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试过这样的事情:
在应用程序控制器中
rescue_from ActiveRecord :: RecordNotFound,ActionController :: RoutingError,
ActionController :: UnknownController,ActionController :: UnknownAction,:NoMethodError,:with => :handle_exception
def handle_exception
render:template => 'error_pages / error'
end
environment / development.rb
config.consider_all_requests_local = false
在哪里可以找到解决方案?
提前感谢...
解决方案
这应该是有效的:
在应用程序控制器中
class NotFound< StandardError的; end
rescue_from NotFound,:with => :handle_exception
def handle_exception
render:template => 'error_pages / error'
end
I'm developing an app with Rails 3.1.2 but I can't find some documentation that works with errors / exception (like 404) on this version of rails.
i have tried things like:
In application controller
rescue_from ActiveRecord::RecordNotFound,ActionController::RoutingError,
ActionController::UnknownController, ActionController::UnknownAction, :NoMethodError, :with => :handle_exception
def handle_exception
render :template => 'error_pages/error'
end
environment/development.rb
config.consider_all_requests_local = false
Where can I find a solution?
Thanks in advance...
解决方案
This should work:
In application controller
class NotFound < StandardError; end
rescue_from NotFound, :with => :handle_exception
def handle_exception
render :template => 'error_pages/error'
end
这篇关于ruby on rails 3.1全局异常处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文