Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jesster2k10 opened this issue Apr 4, 2020 · 0 comments
Open

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

jesster2k10 opened this issue Apr 4, 2020 · 0 comments

Comments

@jesster2k10
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant