Skip to content

Commit

Permalink
Edited lib/rails3-jquery-autocomplete/orm/active_record.rb via GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
slash4 committed Sep 22, 2011
1 parent d562be4 commit eab3098
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/rails3-jquery-autocomplete/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_autocomplete_order(method, options, model=nil)
def get_autocomplete_items(parameters)
model = parameters[:model]
term = parameters[:term]
method = parameters[:method]
method = Array(parameters[:method])
options = parameters[:options]
scopes = Array(options[:scopes])
limit = get_autocomplete_limit(options)
Expand All @@ -29,14 +29,23 @@ def get_autocomplete_items(parameters)

def get_autocomplete_select_clause(model, method, options)
table_name = model.table_name
(["#{table_name}.#{model.primary_key}", "#{table_name}.#{method}"] + (options[:extra_data].blank? ? [] : options[:extra_data]))
(["#{table_name}.#{model.primary_key}", "#{table_name}.#{method.first}"] + (options[:extra_data].blank? ? [] : options[:extra_data]))
end

def get_autocomplete_where_clause(model, term, method, options)
table_name = model.table_name
is_full_search = options[:full]
like_clause = (postgres? ? 'ILIKE' : 'LIKE')
["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]


rep = [method.map{|m| "LOWER(#{table_name}.#{m}) #{like_clause} ? " }.join('or ')]
method.map{|m|
rep << "#{(is_full_search ? '%' : '')}#{term.downcase}%"
}

rep


end

def postgres?
Expand Down

0 comments on commit eab3098

Please sign in to comment.