ruby on rails named scopes (searching)
Posted
by houlahan
on Stack Overflow
See other posts from Stack Overflow
or by houlahan
Published on 2010-04-21T14:54:39Z
Indexed on
2010/04/21
15:03 UTC
Read the original article
Hit count: 132
ruby-on-rails
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
© Stack Overflow or respective owner