Skip to content

Commit bd843ce

Browse files
committed
Update lib/rails3-jquery-autocomplete/orm/mongoid.rb
:scope support for mongoid
1 parent abc6e3a commit bd843ce

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: lib/rails3-jquery-autocomplete/orm/mongoid.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ def get_autocomplete_items(parameters)
2121
term = parameters[:term]
2222
limit = get_autocomplete_limit(options)
2323
order = get_autocomplete_order(method, options)
24+
scopes = Array(options[:scopes])
2425

2526
if is_full_search
2627
search = '.*' + term + '.*'
2728
else
2829
search = '^' + term
2930
end
30-
items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
31+
32+
items = model.scoped
33+
scopes.each { |scope| items = items.send(scope) } unless scopes.empty?
34+
35+
items = items.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
3136
end
3237
end
3338
end

0 commit comments

Comments
 (0)