ruby on rails named scopes (searching)
- by houlahan
I have a named scope (name) combination of first and last name and I'm wanting to use this in a search box.
I have the code below:
named_scope :full_name, lambda { |fn| {:joins => :actor, :conditions => ['first_name LIKE ? OR second_name LIKE ?', "%#{fn}%", "%#{fn}%"]} }
def self.search(search)
if search
self.find(:all, :conditions => [ 'full_name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
but this doesn't work as it gives the following error:
SQLite3::SQLException: no such column: full_name: SELECT * FROM "actors" WHERE (full_name LIKE '%eli dooley%')
Thanks in advance
Houlahan