我有以下命名范围:

named_scope :report_search, lambda { |search|
  {
    :conditions => ["rep_name like ? or rep_id like ? or rep_symbol like ? or rep_issue like ?", search]
  }
}

当我运行它时,我收到错误消息:
wrong number of bind variables

如果有人可以帮助我找出代码的错误,我将不胜感激。

非常感谢

最佳答案

在bind语句中,每个问号都需要一个变量。如果它们都相同,则需要重复多次:

named_scope :report_search, lambda { |search|
  {
    :conditions => ["rep_name like ? or rep_id like ? or rep_symbol like ? or rep_issue like ?", search, search, search, search]
  }
}

关于ruby-on-rails - 命名范围-绑定(bind)变量的数量错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9808071/

10-16 00:14