我有一种奇怪的要求我想彻底改变rails中无路由匹配的行为,而不是引发异常或自定义页面我想在我得到另一台服务器时进行HTTP调用404 /轨道中没有路由匹配。目前我做错了方式
rescue_from ActionController::RoutingError, :with => :render_not_found
def record_not_found
#HTTP call
end
但它不起作用。我是否需要更改RoutingError默认的rails类? 感谢
答案 0 :(得分:0)
没有路由匹配[GET]“不是异常。这只是一个错误,这使得在开发环境中调试变得容易。如果你想处理它,那么在路由中使用下面提到的代码。 rb文件。
确保在所有其他路线定义的末尾定义此配置。如果没有路线匹配,则会搜索中定义的'record_not_found'操作> application_controller
#routes.rb
get '*path',
controller: 'application',
action: 'record_not_found'
#application_controller.rb
class ApplicationController < ActionController::Base
def record_not_found
#add your call to another server
render nothing: true
end
end
希望有所帮助:)