Sha256: cad331c6d0ae92097bf0f1f5b7f57f64dc33bacbb2c4e55a6d6127503a5e0de7
Contents?: true
Size: 1.01 KB
Versions: 11
Compression:
Stored size: 1.01 KB
Contents
module Rails3JQueryAutocomplete module Orm module Mongoid 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) if is_full_search search = '.*' + term + '.*' else search = '^' + term end items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems