ActionController::RoutingError(没有路由匹配 [GET] "/google83362a7a0f381ff0.html"):
- 我在生产中看到了上面的日志,我该如何预防。
- 如果用户输入错误的 URL,我应该如何重定向到常见错误页面
最佳答案
如果没有路由匹配,您可以将用户重定向到您想要的页面
在 routes.rb 文件的底部写下以下代码
在/config/routes.rb
#If no route matches
match ":url" => "application#redirect_user", :constraints => { :url => /.*/ }
然后将用户重定向到application_controller.rb文件中的错误页面
*在/app/controllers/application_controller.rb*
def redirect_user
redirect_to '/404'
end
关于ruby-on-rails - 如何防止生产中出现不必要的路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17678087/