Rails gem rails3-jquery-autocomplete: How do I query multiple fields

Viewed 8072

I'm using the rails3-jquery-autocomplete gem found here: http://github.com/crowdint/rails3-jquery-autocomplete

The instructions are clear for how to query a single attribute of a model and I am able to make that work without a problem.

My Person model has two attributes that I would like to combine and query, however. They are first_name and last_name. I would like to combine them into a pseudo-attribute called full_name. Currently, I receive this error:

ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: full_name: SELECT     "people".* FROM       "people"  WHERE     (LOWER(full_name) LIKE 'cla%') ORDER BY  full_name ASC LIMIT 10):

There is no full_name attribute of the Person model, though I have the following method in the Person model file:

def full_name
  "#{self.first_name} #{self.last_name}"
end

How do I modify the Person model file so that calls to full_name queries the database to match a combination of first_name and last_name?

6 Answers
Related