Rails 3 类方法与 select("...") 给出了错误数量的参数
我希望使用这种方法
@results = Candidate.all.match_against(options)
,其中“选项”是整数数组。它应该向我返回所有候选人的比赛分数。
在候选模型中,我有一种方法可以将候选者与作为参数给出的选项进行匹配。
def self.match_against(cu_options)
select("candidates.id, candidates.first_name, candidates.last_name, candidates.number,
sum(case when c_answers.option_id in (?) then 1 else 0 end) as score", cu_options)
.joins("join answers as c_answers on c_answers.user_id = candidates.user_id")
.joins("join options on c_answers.option_id = options.id")
.where("options.ordering >= 0")
.group("candidates.id, candidates.number, candidates.first_name, candidates.last_name")
end
由于某种原因,当我调用此方法时,它给了我一个错误,
ArgumentError: wrong number of arguments (2 for 1)
from /home/mika/.rvm/gems/ruby-1.9.2-p180@vaalikone/gems/activerecord-3.0.7/lib/active_record/relation/query_methods.rb:34:in `select'
from /home/mika/.rvm/gems/ruby-1.9.2-p180@vaalikone/gems/activerecord-3.0.7/lib/acteve_record/base.rb:442:in `select'
from /home/mika/projects/vaalikone/app/models/candidate.rb:35:in `match_against'
...
我不知道第二个参数来自哪里。我只传递一个参数。我正在使用 postgresql。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您将两个参数传递给选择范围:
sum(case when c_answers.option_id in (?) then 1 else 0 end) as Score"
这有什么原因吗?
Actually, you are passing two arguments to the select scope:
sum(case when c_answers.option_id in (?) then 1 else 0 end) as score"
Is there any reason for that?