3

I'm using the Ahoy gem to get visit information. But I notice in production, I'm frequently getting the below error:

No route matches [GET] "/ahoy/visits"

But the traceback doesn't show any files I recognize. Here's the full trace:

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

Is this just a bot crawling all URLs? How can I find out where it's originating from based on the trace?

Jackson Cunningham
  • 4,973
  • 3
  • 30
  • 80
  • I'm having the same issue here. Did you manage to track it down? – Betjamin Richards Aug 09 '16 at 07:39
  • Yeah actually - you can create a route to ahoy/visits, then create a controller action and just redirect back to root_url – Jackson Cunningham Aug 09 '16 at 21:39
  • Ok, thanks. So where's the origin of the request coming from? Is it crawler bots picking up the URL in the JS or from the actual rails engine itself? – Betjamin Richards Aug 10 '16 at 08:05
  • A problem similar to this error came to me. [That's how I resolved this error.](https://stackoverflow.com/questions/47220823/ahoy-events-post-error-in-rails/47225383#47225383) – Emre Nov 11 '17 at 07:18

2 Answers2

1

You need to mount the ahoy engine in your routes.rb file:

mount Ahoy::Engine => "/ahoy", as: :my_ahoy
gualopezb
  • 334
  • 3
  • 10
1

The cause of this problem seems to be bots crawling into places they shouldn't go. We solved this problem by adding a line to our robots.txt file:

User-agent: *
Disallow: /ahoy/

This should prevent bots from trying any route that begins with /ahoy/ such as our /ahoy/visits route. Not all bots respect the robots.txt file, but enough of them do that we now only rarely see this error occur.

Greyphilosophy
  • 149
  • 2
  • 3