module AutocompleteActiveAdmin::Autocomplete

Public Class Methods

included(target) click to toggle source
# File lib/autocomplete-activeadmin/autocomplete.rb, line 3
def self.included(target)
  target.extend AutocompleteActiveAdmin::Autocomplete::ClassMethods

  target.send :include, AutocompleteActiveAdmin::Orm::Mongoid if defined?(Mongoid::Document)
  target.send :include, AutocompleteActiveAdmin::Orm::MongoMapper if defined?(MongoMapper::Document)
  target.send :include, AutocompleteActiveAdmin::Orm::ActiveRecord

end

Public Instance Methods

get_autocomplete_limit(options) click to toggle source

Returns a limit that will be used on the query

# File lib/autocomplete-activeadmin/autocomplete.rb, line 81
def get_autocomplete_limit(options)
  options[:limit] ||= 10
end
get_object(model_sym) click to toggle source

Returns parameter model_sym as a constant

get_object(:actor)
# returns a Actor constant supposing it is already defined
# File lib/autocomplete-activeadmin/autocomplete.rb, line 90
def get_object(model_sym)
  object = model_sym.to_s.camelize.constantize
end
json_for_autocomplete(items, method, extra_data=[]) { |items| ... } click to toggle source

Returns a hash with three keys actually used by the Autocomplete jQuery-ui Can be overriden to show whatever you like Hash also includes a key/value pair for each method in extra_data

# File lib/autocomplete-activeadmin/autocomplete.rb, line 99
def json_for_autocomplete(items, method, extra_data=[])
  items = items.collect do |item|
    hash = HashWithIndifferentAccess.new({"id" => item.id.to_s, "label" => item.send(method), "value" => item.send(method)})
    extra_data.each do |datum|
      hash[datum] = item.send(datum)
    end if extra_data
    # TODO: Come back to remove this if clause when test suite is better
    hash
  end
  if block_given?
    yield(items)
  else
    items
  end
end