3

我正在使用 Ahoy gem 来获取访问信息。但我注意到在生产中,我经常收到以下错误:

没有路线匹配 [GET] "/ahoy/visits"

但是回溯没有显示我识别的任何文件。这是完整的跟踪:

ActionController::RoutingError: No route matches [GET] "/ahoy/visits"
... 27 non-project frames
1
File "/app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/debug_exceptions.rb" line 21 in call
2
File "/app/vendor/bundle/ruby/2.0.0/gems/rollbar-2.6.3/lib/rollbar/middleware/rails/show_exceptions.rb" line 22 in call_with_rollbar
3
File "/app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/show_exceptions.rb" line 30 in call
4
File "/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.2/lib/rails/rack/logger.rb" line 38 in call_app
5
File "/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.2/lib/rails/rack/logger.rb" line 20 in block in call
6
File "/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb" line 68 in block in tagged
7
File "/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb" line 26 in tagged
8
File "/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb" line 68 in tagged
9
File "/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.2/lib/rails/rack/logger.rb" line 20 in call
10
File "/app/vendor/bundle/ruby/2.0.0/gems/ahoy_matey-1.2.1/lib/ahoy/engine.rb" line 15 in block in call_with_quiet_ahoy
11
File "/app/vendor/bundle/ruby/2.0.0/gems/ahoy_matey-1.2.1/lib/ahoy/logger_silencer.rb" line 44 in silence_logger
12
File "/app/vendor/bundle/ruby/2.0.0/gems/ahoy_matey-1.2.1/lib/ahoy/engine.rb" line 14 in call_with_quiet_ahoy
13
File "/app/vendor/bundle/ruby/2.0.0/gems/request_store-1.2.1/lib/request_store/middleware.rb" line 8 in call
14
File "/app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/request_id.rb" line 21 in call
15
File "/app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/methodoverride.rb" line 22 in call
16
File "/app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/runtime.rb" line 18 in call
17
File "/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/cache/strategy/local_cache_middleware.rb" line 28 in call
18
File "/app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/static.rb" line 113 in call
19
File "/app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/sendfile.rb" line 113 in call
20
File "/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.2/lib/rails/engine.rb" line 518 in call
21
File "/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.2/lib/rails/application.rb" line 164 in call
22
File "/app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/lock.rb" line 17 in call
23
File "/app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/content_length.rb" line 15 in call
24
File "/app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb" line 88 in service
25
File "/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb" line 138 in service
26
File "/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb" line 94 in run
27
File "/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb" line 295 in block in start_thread

这只是一个爬取所有 URL 的机器人吗?如何根据跟踪找出它的来源?

4

2 回答 2

1

这个问题的原因似乎是机器人爬到了他们不应该去的地方。我们通过在 robots.txt 文件中添加一行来解决这个问题:

User-agent: *
Disallow: /ahoy/

这应该可以防止机器人尝试任何以 /ahoy/ 开头的路线,例如我们的 /ahoy/visits 路线。并非所有机器人都尊重 robots.txt 文件,但其中有足够多的机器人这样做,我们现在很少看到此错误发生。

于 2019-02-28T21:51:22.323 回答
0

您需要在routes.rb文件中安装 ahoy 引擎:

mount Ahoy::Engine => "/ahoy", as: :my_ahoy
于 2018-03-10T21:21:45.463 回答