Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

named scope - wrong number of bind variables

I have the following named scope:

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

When i run it, I get the error message:

wrong number of bind variables

I would appreciate it if somebody could help me figure out wht's wrong with the code.

Many thanks

like image 879
Kim Avatar asked Mar 21 '12 15:03

Kim


1 Answers

You can use named bind variables if you don't want to repeat the input.

named_scope :report_search, lambda { |search|
  {
    :conditions => ["  rep_name   LIKE :search OR 
                       rep_id     LIKE :search OR 
                       rep_symbol LIKE :search OR 
                       rep_issue  LIKE :search", :search => search]
  }
}
like image 104
Harish Shetty Avatar answered Sep 20 '22 09:09

Harish Shetty