From 4facc5a32ec5d3da98fad62bd3b94c2721e42cf6 Mon Sep 17 00:00:00 2001 From: pzupan Date: Sun, 23 Oct 2011 06:58:17 -0700 Subject: [PATCH 1/2] Update lib/rails3-jquery-autocomplete/orm/active_record.rb --- lib/rails3-jquery-autocomplete/orm/active_record.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rails3-jquery-autocomplete/orm/active_record.rb b/lib/rails3-jquery-autocomplete/orm/active_record.rb index e9260dd0..f2519d72 100644 --- a/lib/rails3-jquery-autocomplete/orm/active_record.rb +++ b/lib/rails3-jquery-autocomplete/orm/active_record.rb @@ -20,7 +20,13 @@ def get_autocomplete_items(parameters) items = model.scoped - scopes.each { |scope| items = items.send(scope) } unless scopes.empty? + unless scopes.empty? + scopes.each do |scope| + scope_method = scope.gsub(/\(.*\)/, "") + scope_params = scope.scan(/\(([^}]+)\)/).flatten[0] + items = items.send(scope_method, scope_params) + end + end items = items.select(get_autocomplete_select_clause(model, method, options)) unless options[:full_model] items = items.where(get_autocomplete_where_clause(model, term, method, options)). From 1a95c488dc725e3ed801ebb55e67a3a80f53c2d8 Mon Sep 17 00:00:00 2001 From: pzupan Date: Sun, 23 Oct 2011 10:08:42 -0700 Subject: [PATCH 2/2] Fix scopes resolution for scopes with lambda --- lib/rails3-jquery-autocomplete/orm/active_record.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rails3-jquery-autocomplete/orm/active_record.rb b/lib/rails3-jquery-autocomplete/orm/active_record.rb index f2519d72..819e16be 100644 --- a/lib/rails3-jquery-autocomplete/orm/active_record.rb +++ b/lib/rails3-jquery-autocomplete/orm/active_record.rb @@ -24,7 +24,11 @@ def get_autocomplete_items(parameters) scopes.each do |scope| scope_method = scope.gsub(/\(.*\)/, "") scope_params = scope.scan(/\(([^}]+)\)/).flatten[0] - items = items.send(scope_method, scope_params) + items = if scope_params.blank? + items.send(scope_method) + else + items.send(scope_method, scope_params) + end end end