crowdint/rails3-jquery-autocomplete — pull request #235 by jana4u (2013-08-13 20:04:46+00:00)
Title: searching using active_record scope

Added ability to use active record scope for search. It enables using complex queries (use OR, JOIN other tables etc.) in search.

Example usage:

In model just add `scope` with lamba and one parameter. In this example it is called `:autocomplete_by_names`:
```ruby
class User < ActiveRecord::Base
scope :autocomplete_by_names, lambda { |query|
select("users.contact_name, users.business_name").where("(users.contact_name LIKE :query OR users.business_name LIKE :query)", :query => query)
}

def name_with_id
"#{business_name.blank? ? contact_name : business_name} (#{id})"
end
end
```
In controller in `autocomplete` call use just `:id` (if you don't want any other column to be selected from database or if you use select in your scope) and add new option `:search_scope` and specify the name of your `scope` `:autocomplete_by_names`:
```ruby
class UsersController < ApplicationController
autocomplete :user, :id, :full => true, :display_value => :name_with_id, :search_scope => :autocomplete_by_names
end
```
All other `autocomplete` options work with this.