Topic: Multipe WHERE clause [SOLVED]

i am trying to find a record but it may be in multiple fields

so i want to add some extra fields to my search

so how can i make this search 2 different fields

def self.search(search)
    if search
      where('email LIKE ? "%#{search}%")
    else
      scoped
    end
  end

Last edited by moiseszaragoza (2012-07-05 18:05:04)

Re: Multipe WHERE clause [SOLVED]

You can chain where clauses:

where('email LIKE ?', "%#{search}%").where('another_field LIKE ?', "%#{search}%")

or if you want to use OR

where('email LIKE ? OR another_field LIKE ?', "%#{search}%", "%#{search}%")

Last edited by themusicman (2012-07-05 17:57:15)

Re: Multipe WHERE clause [SOLVED]

Thanks
i really like the first one.