ruby-on-rails - ArgumentError:参数数量错误(给定 0,预期 2..3)
问题描述
我正在尝试让 searchkick 工作,但是当我尝试通过控制台重新索引我的故事时遇到错误。我似乎无法理解错误可能是什么,并且希望得到一些帮助。
输入“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 模型:
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
任何人都可以帮助解释正在发生的事情以及解决它的方法吗?我对 Ruby 还是很陌生。
提前谢谢你。
解决方案
推荐阅读
- css - 如果身体高度发生变化,CSS3 全角背景动画
- amazon-web-services - 如何向 URL 发送简单的 GET 并在 Lambda 中查看响应?
- java - 重复的链表
- java - collectionGroup() 不是公开的。无法从外部包访问
- .htaccess - 添加过期标题 Plesk
- r - R图中的Unicode字符 - pdf设备
- django - 在 elasticsearch-dsl 中定义完成建议字段的权重
- swift - 导航到 App Store 的推送通知中的深度链接:- 深度链接问题
- dialogflow-es - @sys.ignore 如何分配给 Dialogflow 实体
- mysql - 无法使用 MAX_USER_CONNECTIONS 在 MariaDB 中创建用户