0

I'm running Rails 5.2 and the awesome Ahoy gem, with mongoid as the ORM.

In the homepage controller, I'm calling current_visit.visitor_token, which is generating the following error:

MONGODB | ds111336.mlab.com:11336 | heroku_1f375nv7.find | STARTED | 
{"find"=>"ahoy_visits", "filter"=>{"visit_token"=>"4f86bf0d-f694-4a46- 
b1fb-4ff48722e5c5"}, "sort"=>{"_id"=>1}, "limit"=>1, 
"singleBatch"=>true}
MONGODB | ds111336.mlab.com:11336 | heroku_1f375nv7.find | SUCCEEDED | 
0.048124999999999994s
Completed 500 Internal Server Error in 297ms (ActiveRecord: 202.8ms)



NoMethodError (undefined method `visitor_token' for nil:NilClass):

The ahoy_visit value stored in the cookie is b5b4fd64-ec42-4e6d-9740-e394ed4a24da, yet Ahoy seems to be searching for a different visit_token (as above).

initializers/ahoy.rb:

class Ahoy::Store < Ahoy::DatabaseStore

end

# set to true for JavaScript tracking
Ahoy.api = true
Ahoy.server_side_visits = true

If I clear the website data from my browser (or open a new session in an incognito window), the error does not occcur until I wait another day (I'm guessing until the sessions expires).

I've searched all through the code and can not figure out why Ahoy is not creating a new visit record in the DB.

Thanks for any help in advance!

benrs44
  • 3
  • 2

1 Answers1

0

With Ahoy 2.0 you visit model need to be scoped as such class Ahoy::Visit < ApplicationRecord # code here end - another walkaround is re-install Ahoy and it will place Visit and Event in the correct location.

Abass Sesay
  • 833
  • 10
  • 18