【发布时间】:2016-05-18 10:19:30
【问题描述】:
我每天都有错误的请求,而不是在 production.log 中生成大量日志,如下所示:
F, [2016-02-08T15:39:17.698761 #2437] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/sites/default/files/elsevier/eop/S0025-7753(12)00231-X.pdf"):
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call...'
在我的网站中没有/sites/`的路由:这是一个外部网络服务错误,我想知道它的IP来解决问题。
我已经学会了这个,但是不起作用,我想我需要一些其他的代码
(我有 Rails 4.0.2,我将很快升级到 4.2.5。)
1- 在routes.rb,最后:
match '*path', :to => 'application#routing_error', via: :all
2- 在application_ontroller:我记录了 IP,然后 如果我在生产中,我需要渲染 404.html,如果我在开发中,我需要正常渲染 rails 错误
def routing_error(error = 'Routing error', status = :not_found, exception=nil)
logger.debug { "---> I catch you #{request.remote_ip}" }
render status: 404, file: "404.html"
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 routing