Sha256: 1be86f2497d66fa8c84c0d79dfd640387e17ec482112b8107883bbd4f7987459
Contents?: true
Size: 952 Bytes
Versions: 15
Compression:
Stored size: 952 Bytes
Contents
module Rails3JQueryAutocomplete module Orm module MongoMapper def get_autocomplete_order(method, options, model=nil) order = options[:order] if order order.split(',').collect do |fields| sfields = fields.split [sfields[0].downcase.to_sym, sfields[1].downcase.to_sym] end else [[method.to_sym, :asc]] end end def get_autocomplete_items(parameters) model = parameters[:model] method = parameters[:method] options = parameters[:options] is_full_search = options[:full] term = parameters[:term] limit = get_autocomplete_limit(options) order = get_autocomplete_order(method, options) search = (is_full_search ? '.*' : '^') + term + '.*' items = model.where(method.to_sym => /#{search}/i).limit(limit).sort(order) end end end end
Version data entries
15 entries across 15 versions & 1 rubygems