【问题标题】:Rails 5.2 & Ahoy 2 - "undefined method `visitor_token' for nil:NilClass"Rails 5.2 & Ahoy 2 - “nil:NilClass 的未定义方法 `visitor_token'”
【发布时间】:2018-06-05 12:31:43
【问题描述】:

我正在运行 Rails 5.2 和很棒的 Ahoy gem,使用 mongoid 作为 ORM。

在主页控制器中,我正在调用current_visit.visitor_token,这会产生以下错误:

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):

存储在 cookie 中的 ahoy_visit 值是 b5b4fd64-ec42-4e6d-9740-e394ed4a24da,但 Ahoy 似乎正在搜索不同的 visit_token(如上)。

initializers/ahoy.rb:

class Ahoy::Store < Ahoy::DatabaseStore

end

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

如果我从浏览器中清除网站数据(或在隐身窗口中打开一个新会话),直到我再等一天(我猜是会话过期)才会出现错误。

我搜索了所有代码,无法弄清楚为什么 Ahoy 没有在数据库中创建新的访问记录。

提前感谢您的帮助!

【问题讨论】:

    标签: mongoid ruby-on-rails-5.2 ahoy


    【解决方案1】:

    在 Ahoy 2.0 中,您访问的模型需要这样限定范围 class Ahoy::Visit < ApplicationRecord # code here end - 另一个解决方法是重新安装 Ahoy,它将访问和事件放置在正确的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      相关资源
      最近更新 更多