1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Rails 5.2 & Ahoy 2 - "undefined method `visitor_token' for nil:NilClass"

Discussion in 'Programming/Internet' started by benrs44, Sep 12, 2018.

  1. benrs44

    benrs44 Guest

    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,
    MONGODB | ds111336.mlab.com:11336 | heroku_1f375nv7.find | SUCCEEDED |
    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).


    class Ahoy::Store < Ahoy::DatabaseStore


    # 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!

    Login To add answer/comment

Share This Page