houlahan
asked on
ruby on rails named scopes (searching)
I have a named scope (full_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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.