ArgumentError: wrong number of arguments (given 0, expected 2..3)
ArgumentError: wrong number of arguments (given 0, expected 2..3)
I'm trying to get searchkick to work but I run into an error when I attempt to reindex my stories via the console. I can't seem to understand what the error might be and would love some help.
The error via the console after entering "Story.reindex":
Story Import (3.6ms) {"count":2,"exception":["ArgumentError","wrong
number of arguments (given 0, expected 2..3)"],"exception_object":"wrong
number of arguments (given 0, expected 2..3)"}
ArgumentError: wrong number of arguments (given 0, expected 2..3)
from app/models/story.rb:42:in `hot_score'
from (irb):1
story.rb model:
class Story < ApplicationRecord
searchkick
has_many :votes
scope :newest, -> { order(created_at: :desc) }
scope :hottest, -> { order(hot_score: :desc) }
def upvotes
votes.sum(:upvote)
end
def downvotes
votes.sum(:downvote)
end
def calc_hot_score
points = upvotes - downvotes
time_ago_in_hours = ((Time.now - created_at) / 3600).round
score = hot_score(points, time_ago_in_hours)
update_attributes(points: points, hot_score: score)
end
private
def hot_score(points, time_ago_in_hours, gravity = 1.8)
(points - 1) / (time_ago_in_hours + 2) ** gravity
end
end
Can anyone help explain what is going on and maybe a way to get around it? I'm still pretty new to Ruby.
Thank you ahead of time.
points
time_ago_in_hours
Where would I find this calling hot_score()? Which files so I can give you an answer?
– miklki14567
2 days ago
What is the output of Story.first.calc_hot_score ?
– archit gupta
2 days ago
It gives the following error
NoMethodError: undefined method
first_calc_hot_score' for Story (call 'Story.connection' to establish a connection):Class`– miklki14567
2 days ago
NoMethodError: undefined method
@miklki14567, I am assuming your in the rails console (
rails c
). This NoMethodError
problem can be fixed by first calling Story.connection
. Also, you said "when I attempt to reindex my stories via the console" you are getting your original error. How exactly are you doing this? What specific commands are you running in console?– possiblyLethal
2 days ago
rails c
NoMethodError
Story.connection
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How are you calling hot_score()? This method takes two arguments:
points
andtime_ago_in_hours
. The error suggests you are not passing in these two arguments.– possiblyLethal
2 days ago