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}%"]} }

  if search
    self.find(:all, :conditions => [ 'full_name LIKE ?', "%#{search}%"])

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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A few  questions/comments:
1) What is the select statement that's being attempted? (check in your development log)
2) Please provide the whole definition of your class
3) In general, isn't named_scope supposed to build the find for you... that would mean that you should be able to execute something like:
rather than the generic find that you are using. You are actually trying to put in two :condition clauses - one from the named_scope and one from the find method itself.
4) I don't understand the ":joins =>" in your lambda. If Actor is your sole model, then I don't think you need that... and I don't think you even need the lambda if that's the case I presume your full_name is "<first name> <last name>", therefore you need to split out the full_name into it's two parts to use the conditions statement. Therfore, I'd suggest (lacking more details) defining your named_scope  and your method something like this (assuming self = Actor):
Named Scope:
named_scope :full_name, lambda { |*args| { :conditions => ['first_name LIKE ? OR second_name LIKE ?', args.first, args.last] } }
  if search
    full_name(search.split(/ /)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.