Skip to content

WARN: NoMethodError: ndefined method `count' for nil:NilClass #124

@jesster2k10

Description

@jesster2k10

Hey, for some reason when you run the following:

# models/user.rb

class User < ApplicationRecord
  recommends :listings, :categories, :tags, :brands
end

you get the following error after performing an action, in the Sidekiq logs

0 WARN: NoMethodError: undefined method `count' for nil:NilClass
2020-04-04T20:15:47.344Z pid=93820 tid=oxbyb6dk0 WARN: /Library/Ruby/Gems/2.6.0/gems/recommendable-2.2.2/lib/recommendable/helpers/calculations.rb:106:in `update_recommendations_for'

The line points to this line in the helpers/calculations.rb file:

          nearest_neighbors = Recommendable.config.nearest_neighbors || Recommendable.config.user_class.count

which suggests that the issue may arise from the config.nearest_neighbors being set to nil and the config.user_class not being set.

However, when you set the config.user_class = User, the application crashed instantly with a bunch of weird errors.

My config/initializers/recommendable.rb looks like:

Recommendable.configure do |config|
  # Recommendable's connection to Redis
  config.redis = Redis.new

  # Whether or not to automatically enqueue users to have their recommendations
  # refreshed after they like/dislike an item
  config.auto_enqueue = true
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions