我希望像
那样使用这个方法@results = Candidate.all.match_against(options)
,其中"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
实际上,您正在向选择范围传递两个参数:
- 字符串"候选者"。id,候选人。first_name、候选人。last_name、candidates.number求和(当c_answers时的情况)。option_id in (?) then 1 else 0 end)作为score" 变量cu_options
这有什么原因吗?